query a port
eight02645999 at yahoo.com
eight02645999 at yahoo.com
Sun Oct 30 01:21:16 EST 2005
thanks alot!
that's all there is to it..so it's just a simple connect.
Dan M wrote:
> On Sat, 29 Oct 2005 20:21:20 -0700, eight02645999 wrote:
>
> > hi
> > in python, how do one query a port to see whether it's up or not?
> > thanks
>
> I'm an absolute beginner, but let's see if I can help. Assuming you want
> to check a port on another machine,
>
> import socket
> port=25 # Port we want to test
> host=machine.to.test # Either IP address or FQDN
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> try:
> s.connect((host, port))
> print "We made the connection"
> except socket.error:
> print "Sorry, that port is not open"
> s.close
>
> Does that help?
>
> Dan
More information about the Python-list
mailing list