473,788 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query a port

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

Oct 30 '05 #1
4 2596
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(s ocket.AF_INET, socket.SOCK_STR EAM)
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
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(s ocket.AF_INET, socket.SOCK_STR EAM)
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
Il 2005-10-30, ei***********@y ahoo.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3068
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20 3, NULL, 9, 82, 25
6
1659
by: scott | last post by:
what is the best way to send data to and query SQL 2005 server express edition db hosted on a dedicated server with ISP ? i need to query it directly from an application on my LAN (asp site on same machine as sql db also needs to query db) i can obviously use port 1433 but what other option do i have ? i.e ssl port, xml web service ? Any information is helpful
7
16551
by: kooch54 | last post by:
I am trying to write a script to simply query the group members in an active directory group. I need to use LDAP to make sure I capture any global global group nestings that may occur. I already have a function that uses WinNT provider to capture this info from NT4 or AD domains and it works beautifully. It just doesn't capture global > global nestings. I am having great difficulties in getting this to work on AD though with ldap. I...
1
4839
by: pretzelboy | last post by:
Hi, I last wrote software 13years ago in the pascal, dbase, clipper days. I have recently built a Ubuntu Box and with C++ (and help from the web) setup a serial barcode reader program using Mysql database tables. All works well, and I can do what I need except I am having some trouble with applying an MySQL query result into a defined variable. This would seem like such an easy thing to do. The only examples I can find out there are...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.