Hi All. The below script seems to work well enough to use but I'm wondering if I'm doing the file edit stuff in a "kosher" manner. I was just reading the Lutz O'Reilly "Learning" book and remembered that strings are immutable. So how was I able to change the strings for my dotted quad? I did not explicitly open a separate file in /tmp and then overwrite the ipf.conf file which seemed like the safer way. Yet somehow the below syntax works.
Also I need to figure out how to update the LASTKNOWN variable after my IP changes. Thanks for any advice. import socket # import fileinput import subprocess import string import re SENDMAIL = "/usr/sbin/sendmail" CURRENT = socket.getaddrinfo(socket.gethostname(), None)[0][4][0] LASTKNOWN = '173.48.204.168' if CURRENT == LASTKNOWN: print 'Nevermind.' subprocess.sys.exit() else: cf = open("/etc/ipf.conf", "r") lns = cf.readlines() lns = "".join(lns) # close it so that we can open for writing later lns = re.sub(LASTKNOWN, CURRENT, lns) cf = open("/etc/ipf.conf", "w") cf.write(lns) cf.close() subprocess.call('/sbin/ipf -Fa -f /etc/ipf.conf', shell=True) subprocess.call('/sbin/ipnat -CF -f /etc/ipnat.conf', shell=True) ptchew = subprocess.Popen("%s -t" % SENDMAIL, "w") ptchew.write("To: m...@blisses.org\n") ptchew.write("Subject: YOUR IP ADDRESS HAS CHANGED\n") ptchew.write("\n") # blank line separating headers from body ptchew.write("Your IP address has changed to: ") ptchew.write(CURRENT) ptchew.write(time.asctime()) ptchew = p.close() -- The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function. -- F. Scott Fitzgerald _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor