[Tutor] Search text file, perform action if a given item found in file

Eric eric at digitalert.net
Thu Sep 9 10:59:56 CEST 2004


Eric wrote:

> This is my first project that I am starting to work on, and what I 
> want to create is a program
> that will alert me by sounding the system bell (beep) when a 
> connection is
> established to a selected TCP, or UDP port. It may not be the most 
> usefull thing, but the
> learning experience is what I'm after with all
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>

Sent  that email  on accident without completing it..


Anyway so far I have come up with this..



import os

PORT = int(raw_input("What tcp/udp should I watch for?: "))

os.popen('netstat -an>log.txt')

LogFile = file('log.txt', 'r')
logcontents = LogFile.read()
inFile.close()
print logcontents




So far so good.  The "print logcontents" will print the output from the 
netstat command. My question is this.
I'm trying to figure out a way to search "logcontents" for the "PORT" 
variable then perfrom a action if it finds
a match.

Thanks



More information about the Tutor mailing list