I want to convert an ip address read from a file in the decimal format (192.168.65.72) to one in binary format {110000001010100001000001010001000}.I am reading the ip address in the decimal format from a file.Find the code snippet below.
/*contains 192.168.65.72*/
filter = open("filter.txt", "r")
for line in filter:
bytePattern = "([01]?\d\d?|2[0-4]\d|25[0-5])"
regObj = re.compile("\.".join([bytePattern]*4))
for match in regObj.finditer(line):
m1,m2,m3,m4 = match.groups()
print "%s %s %s %s" %(m1, m2, m3, m4)
I want to convert m1,m2,m3 and m4 each into an 8bit binary value.I cannot figure out a way to do that.I am new to python.Any help will be greatly appreciated.
Cheers.