[Tutor] sending both a filename and an argument from the command
line
Ben Vinger
bvinger at postmaster.co.uk
Sun Nov 23 06:39:58 EST 2003
Hi
OK, thanks to that advice, it works, but behaves strangely. (it prints the correct output, but also some comments and code to the console)
#!/usr/bin/env python
# example how to take a filename and an ip address as command line arguments
# python ip.py capture.txt --ip 66.218.71.109
import os, sys, fileinput, optparse
from optparse import OptionParser
parser = OptionParser()
parser.add_option("--ip", dest="ip address to test", help="example: python ip.py capture.txt --ip 66.218.71.109")
options, argv = parser.parse_args(sys.argv)
for line in fileinput.input(argv):
if line.find(sys.argv[3]) > 0:
print line
The output of
python ip.py capture.txt --ip 66.218.71.109
looks like this (note the unwanted lines from the script):
# python ip.py capture.txt --ip 66.218.71.109
parser.add_option("--ip", dest="ip address to test", help="example: python ip.py capture.txt --ip 66.218.71.10
9")
47742.225111 192.168.1.200 -> 66.218.71.109 TCP 5237 > http [FIN, ACK] Seq=3976725456 Ack=3429041443 Win=65287
Len=0
Thanks
Ben
On Sat, 22 Nov 2003 16:55:36 -0800 (PST) , Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
___________________________________________________
Take your business online with Officemaster. Sign up for a free trial today!
http://www.officemaster.net
More information about the Tutor
mailing list