[Tutor] Search text file, perform action if a given item found
in file
Eric
eric at digitalert.net
Fri Sep 10 10:31:31 CEST 2004
I'm still new to this so please bare with me. I have spent a few hours
searching google, and trying different combinations
and can't seem to figure out how to use endswith() to search a list, and
to then take a action. In my case I would want to search through
"l.split()[1:2]" for
the port number, and from there depending on if it finds a match it
would go through a if-else statement, and then loop back
to he start to continue monitoring. I think I can handle the second
part, but searching a list, and taking a action based on that search is
somehting
that I am having a hard time grasping. Any help would be greatly greatly
appreciated.
This is the output of print l.split()[1:2]
[]
['Connections']
[]
['Local']
['0.0.0.0:135']
['0.0.0.0:445']
['127.0.0.1:1028']
['127.0.0.1:1067']
['127.0.0.1:1068']
['127.0.0.1:1205']
['127.0.0.1:1206']
['172.16.0.2:139']
['192.168.0.250:139']
['192.168.0.250:1158']
['192.168.0.250:1159']
['192.168.0.250:1507']
['0.0.0.0:445']
['0.0.0.0:500']
['0.0.0.0:4500']
['127.0.0.1:123']
['127.0.0.1:1057']
['127.0.0.1:1900']
['172.16.0.2:123']
['172.16.0.2:137']
['172.16.0.2:138']
['172.16.0.2:1900']
['192.168.0.250:123']
['192.168.0.250:137']
['192.168.0.250:138']
['192.168.0.250:1900']
>>
>> Next you probably want to split() the line to divide it into fields.
>> Then you can look at the specific fields. You might be able to use
>> endswith() or find() to search for the port; in my example
>> endswith(':25') for example would find the line with port 25. The
>> details depend on what your data looks like.
>>
>> Give this a try and let us know how far you get. Also it would be
>> helpful to see an example of the output of netstat on your computer,
>> it is different on Windows and MacOSX.
>>
>> Kent
>
More information about the Tutor
mailing list