I have the following in my python script..
hostIP = sys.argv[1]
hostsFileLoc = "hosts.txt"
if not hostIP in open(hostsFileLoc).read():
# Script to add if the string is not in file
else:
# Print message
The only problem with this is that it is not an exact match, for example...
If my file contains:
192.168.0.111
And my hostIP is:
192.168.0.11
Then it will find it as a match. I thought I might be able to do this with regex, as there will always be a space ("\s+") or a comma ("\,") so I thought I could use something like
test = re.compile("^" + hostIP + "[\s\,]*")
and use test as my search, but this obviously does not work. I've tried to find some documentation on this but to no avail. Has anyone a suggestion on how I can use a variable with regex to have a more specific search.
Thanks
MHibbin