I am trying to convert a file which contains ip address in the traditional format to a file which contains ip address in the binary format.
the file contents are as follows.
src-ip{ 192.168.64.54 } dst-ip{ 192.168.43.87 }
The code i have is as follows.
import re
from decimal import *
filter = open("filter.txt", "r")
output = open("format.txt", "w")
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()
line = line.replace((' '.join([bin(256 + int(x))[3:] for x in '123.123.123.123'.split('.')])),bytePattern)
print line
The portion line.replace() does not seem to be working fine.the first parameter to line .replace is working fine.(i.e it is converting the ip address into the binary format.) but line.replace doesn't seem to work.Any help or clues as to why this happens is appreciated.
Thanks in advance. Karthik.