Python Script : Convert IPs to Hex

So you need to convert IP to Hex in regular basis. Till now you may be doing so manually, or by using some online tool. My script will convert all IPs to Hex at Once !!!

import fileinput, sys, os, subprocess
import binascii
import socket
open('hexfile.txt', 'w').close()
subprocess.call(['notepad.exe', 'hexfile.txt'])
for line in fileinput.input('hexfile.txt', inplace = True):
    line = binascii.hexlify(socket.inet_aton(line)).upper()
    line = line + '\n'
    sys.stdout.write(line)
subprocess.call(['notepad.exe', 'hexfile.txt'])
os.remove('hexfile.txt')



-----------------------------------------------------------------------------------------------------------------

Notes:

1. Opens a notepad. Put one IP in one line. This will convert all IP's to Hex.

2. You are not entering any input to python console, so if you save this file with extension with .pyw instead of .py, then python console will not open and a notepad will be open directly.

3. binascii ??

Its a standard module, available by default, that contains a number of methods to convert between binary and various ASCII-encoded binary representations.
 

Comments