By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

query a port

P: n/a
hi
in python, how do one query a port to see whether it's up or not?
thanks

Oct 30 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Oct 30 '05 #2

P: n/a
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


Oct 30 '05 #3

P: n/a
Il 2005-10-30, ei***********@yahoo.com <ei***********@yahoo.com> ha scritto:
hi
in python, how do one query a port to see whether it's up or not?
thanks


Have a look at this:
http://aspn.activestate.com/ASPN/Coo.../Recipe/286240
--
Lawrence
http://www.oluyede.org/blog
Oct 30 '05 #4

P: n/a
On Sat, 29 Oct 2005 23:21:16 -0700, eight02645999 wrote:
thanks alot!
that's all there is to it..so it's just a simple connect.


If all you want to do is check that the given port is open on the given
host, that's it. I tried it on my local box. When connecting to port 25,
it made the connection fine. Trying to connect to port 26 raised a
socket.error.

Oct 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.