Determining if a Port is Open - SNMP Indy

I am using SNMP to retrieve data from devices, using port 161. As I would like to run multiple programs communicating with different devices I need to determine if another version of the program is using the port before trying to create the connection. While I have tried using an example I have found I am not able to make this work. If anyone has some code they would be willing to share that would be much appreciated. (I also need to know how to insert the IP address of the NIC into the query.)  (I trust 
that this makes sense - any help would be much appreciated. I would like to use this on both a PC and Android.)   Thank you.  John Docherty
0
John
6/4/2015 9:07:35 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

4 Replies
956 Views

Similar Articles

[PageSpeed] 14

John wrote:

> I am using SNMP to retrieve data from devices, using port 161. As
> I would like to run multiple programs communicating with different
> devices I need to determine if another version of the program is
> using the port before trying to create the connection.

Each TIdSNMP socket will use a unique local IP/Port when sending messages, 
whether you bind the socket explicitly, or let the socket bind itself implicitly. 
 Even if multiple TIdSNMP instances were communicating with the save device 
at the same time, it should be receiving messages from unique IP/Port pairs. 
 As long as the device is sending each response to the same IP/Port that 
sent the request (which it should be), everything should work fine, you do 
not need to do anything special.

> I also need to know how to insert the IP address of the NIC into
> the query.

It already is, at the UDP layer.  When the device receives the query, it 
will have access to the IP/Port of the sender from the UDP message header. 
 The only gotcha would be if the query is passing through a router/NAT, but 
you want the sender's original IP to appear in the query message data.  In 
that case, you would have to explicitly bind TIdSNMP (via its BoundIP, BoundPort(Min|Max), 
and Active properties) to a specific NIC beforehand so you can then retreive 
the bound IP/Port when formatting the query data.

> I would like to use this on both a PC and Android

The behavior I described works the same on all platforms.

-- 
Remy Lebeau (TeamB)
0
Remy
6/4/2015 5:15:38 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> John wrote:
> 
> > I am using SNMP to retrieve data from devices, using port 161. As
> > I would like to run multiple programs communicating with different
> > devices I need to determine if another version of the program is
> > using the port before trying to create the connection.
> 
> Each TIdSNMP socket will use a unique local IP/Port when sending messages, 
> whether you bind the socket explicitly, or let the socket bind itself implicitly. 
>  Even if multiple TIdSNMP instances were communicating with the save device 
> at the same time, it should be receiving messages from unique IP/Port pairs. 
>  As long as the device is sending each response to the same IP/Port that 
> sent the request (which it should be), everything should work fine, you do 
> not need to do anything special.
> 
> > I also need to know how to insert the IP address of the NIC into
> > the query.
> 
> It already is, at the UDP layer.  When the device receives the query, it 
> will have access to the IP/Port of the sender from the UDP message header. 
>  The only gotcha would be if the query is passing through a router/NAT, but 
> you want the sender's original IP to appear in the query message data.  In 
> that case, you would have to explicitly bind TIdSNMP (via its BoundIP, BoundPort(Min|Max), 
> and Active properties) to a specific NIC beforehand so you can then retreive 
> the bound IP/Port when formatting the query data.
> 
> > I would like to use this on both a PC and Android
> 
> The behavior I described works the same on all platforms.
> 
> -- 
> Remy Lebeau (TeamB)

Remy,

Thank you for your detailed reply. I will look at this further. I should have mentioned that I asked this question as when I try to run two programs at the same time I receive the following error:-

Exception EIdCouldNotBindSocket in module ....exe at ....
Could not bind socket. Address and port are already in use.

I presume that this may indicate that I am doing something else incorrectly.  

Thank you - I appreciate your assistance.

Regards,

John Docherty
0
John
6/4/2015 7:45:11 PM
John wrote:

> when I try to run two programs at the same time I receive the
> following error:-
> 
> Exception EIdCouldNotBindSocket in module ....exe at .... Could
> not bind socket. Address and port are already in use.

That happens when explicitly binding a socket to the same local IP/Port that 
another socket is already using (or had recently used, if the IP/Port is 
still in TIME_WAIT state after the socket was closed).  TIdSNMP does not 
explicit bind its primary socket, unless you ask it to do so via the BoundIP/BoundPort 
properties.

However, TIdSNMP does create and explicitly bind a secondary socket for receiving 
SNMP traps, and that may be where your exception is coming from.  The TIdSNMP.TrapPort 
property is 162 by default to enable trap reception.  When TIdSNMP creates 
its primary socket, it also binds the trap socket to the bound IP of the 
primary socket.  So, if you were running two TIdSNMP objects on the same 
machine, and both were bound to the same NIC, and both tried to bind their 
trap sockets to the same port, that would be an error condition.  You cannot 
have multiple TIdSNMP objects listening for traps on the same IP/Port at 
the same time.  So either assign unique BoundIP/TrapPort values to each one, 
or set TrapPort to 0 to disable trap reception in at least one of them.

-- 
Remy Lebeau (TeamB)
0
Remy
6/4/2015 9:06:49 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> John wrote:
> 
> > when I try to run two programs at the same time I receive the
> > following error:-
> > 
> > Exception EIdCouldNotBindSocket in module ....exe at .... Could
> > not bind socket. Address and port are already in use.
> 
> That happens when explicitly binding a socket to the same local IP/Port that 
> another socket is already using (or had recently used, if the IP/Port is 
> still in TIME_WAIT state after the socket was closed).  TIdSNMP does not 
> explicit bind its primary socket, unless you ask it to do so via the BoundIP/BoundPort 
> properties.
> 
> However, TIdSNMP does create and explicitly bind a secondary socket for receiving 
> SNMP traps, and that may be where your exception is coming from.  The TIdSNMP.TrapPort 
> property is 162 by default to enable trap reception.  When TIdSNMP creates 
> its primary socket, it also binds the trap socket to the bound IP of the 
> primary socket.  So, if you were running two TIdSNMP objects on the same 
> machine, and both were bound to the same NIC, and both tried to bind their 
> trap sockets to the same port, that would be an error condition.  You cannot 
> have multiple TIdSNMP objects listening for traps on the same IP/Port at 
> the same time.  So either assign unique BoundIP/TrapPort values to each one, 
> or set TrapPort to 0 to disable trap reception in at least one of them.
> 
> -- 
> Remy Lebeau (TeamB)

Remy,

Thanks very much for your reply. I have set the TrapPort to 0 as suggested; this seems to have solved the problem. 

(I now have two versions of the program running simultaneously retrieving data separately which is what I was wanting to do.)

Thank you. 

Regards

John Docherty
0
John
6/7/2015 1:09:59 AM
Reply:

Similar Artilces:

UDP Port Open doesnt mean the port is open
Related to the other threads that are ongoing regarding a similar issue it SEEMS as if some people might be concerned because UDP ports are being shown as open when they are running being a Stealthing device. This does not mean that your ports are in fact open. This problem i sbeing cause by the way in which the UDP protocol works. Since it is a connectionless protocol there is no set-up or tear down of connections. Packets are puched out of the computer like a mother bird teaching her babies to fly. If they make it they make it. typically the way a port scan would see a closed UD...

Open Ports what opened them
How I find out what program has opened a port on my computer. port 2105 -- There is an old Vulcan proverb. Only Nixon could go to China. Brady Wang wrote: > How I find out what program has opened a port on my computer. You can use AtGuard (no longer available), Norton Internet Security / Norton Personal Firewall (non free) <http://www.symantec.com>, TCPView Pro (non free) <http://www.winternals.com/>, Fport (free but NT/2000 only) <http://www.foundstone.com/> and a few other tools. Sebastian ...

port 27960 and open ports
I am running zone alarm at the high security level and I am getting blasted with port scans over port 27960. when I goto shields up and test my system I find I have a whole bunch of ports open. This is wierd because I have checked my system before and all ports were stealthed. I have tried to disable port 180 via unbinding TCIP from every thing but it still seems to be open ! Any suggestions. Hi! Go there and click on port 180 and you will have more info: http://www.netice.com/Advice/Exploits/Ports/ HTH -- -- Pentab ��� ��� The Deranged Paranoid ��� ***Addy invalid---Re...

Port forwarding/open ports?
To be able for another person to connect to my Netmeeting (conf.exe)in Windows XP and share applications I would need to open the ports 1720 and 1503 in my router firewall. My wonder is how much more vulnerable I will be if I do that? It would be nice not to have to open and close those ports over and over again in my router firewall when I need it and instead having them open all the time so it will just be to start Netmeeting when I need to collaborate and share applications. - Is it just a risk (bigger or smaller?) when I have Netmeeting started since I suppose some good...

Converting Delphi 2007 Indy 10.2.3 to Delphi 2009 Indy 10.5.5 [Edit]
Hello, I am currently attempting to port over a Delphi 2007 project that uses Indy 10.2.3 (very successfully) to Delphi 2009 and Indy 10.5.5 (I just got the latest development build this morning). I think I am running into an encoding issue, but am not sure. Specifically, IDHTTP with SSL calls an old CGI and the CGI returns a .zip file and I then save it to the disk. In 2007 and before this worked perfectly. In 2009, it is not. Here is the examples of the 2 different results (though cut way short in the post) I am getting back: 2007: 'PK'#3#4#$14#0#0#0#8#0'rLQ9žrPb€'#0...

Code Porting
Hi people, Basically, I am moving an app from Delphi 5 to Delphi 2009 which is all great (yeah right!) and I am having a couple of issues with some thirdparty components that we have the source code for. Being that I wanted to make the task as easy as possible, I was able to download the component in Delphi 2007 format. I have now managed to port that to 2009 so it compiles only with warnings and no errors. So all is good at this moment. Now I am trying to install the component into the IDE by using the install menu option from the project manager. This is where I run into errors. ...

delphi 7 Indy 9 and Indy 10
Hi, I can upgrade to indy 10 in delphi 7. But I have discover that indy 9 and Indy 10 have some different properties, so i had to change my old programs that were made in indy 9 to upgrade it to new version, but it is a long work. So I want to know if it is possible to install in the same delphi 7 both versions indy 10 and indy 9. I have tried to do it but i received a error message: Cannot load package 'IndySystem70'. It contains unit 'IdWinSock2', which is also contained in package 'Indy70'. Some can give me ideas or a link to read how to install both versi...

Service ports scan misses open ports
When I run the normal scan it correctly identifies 2 ports that are intentionally open on my machine (It's running a couple of servers) however, when I run the full service ports scan it often misses them. There are actually 3 open ports and it seems to randomly detect them when it feels like it. Sometimes it does sometimes it doesn't, I have tried several times and it never shows all 3 open at any one time. -- Regards, Simon Wones [Simon Wones] wrote ... > When I run the normal scan it correctly identifies 2 ports that > are intentionally open on my machine (...

Port 1036 Open and Port 80 closed?
Hi, I'm somewhat new to closing ports and all. But from Shieldsup, I saw that it can find Port 80, but it is closed. And it can also find Port 1036 and open. How can I either close or stealth 1036 and how can I stealth port 80? I know that when I check Port 1036, it says: pcg-radar RADAR Service Protocol That means what? And is having the ports stealth better than having them closed? Thanks P.S. I'm using ZoneAlarm and a Router. On Mon, 6 Jun 2005 21:09:41 -0400, Daniel O wrote: > Hi, I'm somewhat new to closing ports and all. But from Shieldsup, I saw ...

Port 53 and port 199 still open
Tried suggestion from Kevin A re customised scan using SU scan. Port 53 is open (showing DNS) Port 199 is open (showing SMUX) Also both are replying to ping requests and solicited TCP packets and therefore fail the stealth test on three grounds. I am using a satellite download service via a broadband PCI receiver card essentially part of a network provided by the service provider. The contol and upload is via dial-up modem, which establishes a VPN connection to the ISP. In this configuration SU scan both general and customised shows both port 53 and 199 open. Eventhough ...

Delphi 2010 and Delphi XE5 shuts down when opening projects
Over the last week I have found it increasingly difficult to open projects. Even really simple projects, some more complex. For example if start Delphi 2010 Enterprise Edition. I see the list of recently opened projects. I then click on a simple existing project, I get a hour glass for about a second and then Delphi IDE has gone. In the windows task manager, there are now no applications running. I have not changed the installation, being using Delphi 2010 enterprise on the same computer for a few years. I'm not a full time developer, but do internal development of our compa...

Use port knocking for a more secure method of opening ports
Use port knocking for a more secure method of opening ports http://techrepublic.com.com/5100-22_11-5481894.html *********************************************************** Quote *********************************************************** Every open port on a firewall or a router is a security risk. That's why a technique called "port knocking" can be valuable. Port knocking is a method of allowing access to firewalled services given a preconfigured "knock." The knock consists of a sequence of access attempts to closed ports on a system. These attempts a...

Delphi 2010 and Delphi XE5 shuts down when opening projects
Over the last week I have found it increasingly difficult to open projects. Even really simple projects, some more complex. For example if start Delphi 2010 Enterprise Edition. I see the list of recently opened projects. I then click on a simple existing project, I get a hour glass for about a second and then Delphi IDE has gone. In the windows task manager, there are now no applications running. I have not changed the installation, being using Delphi 2010 enterprise on the same computer for a few years. I'm not a full time developer, but do internal development of our compa...

Opening COM ports, Writing and Reading COM ports.
I am in desperate need of sample powerscript code to open a serial COM port from PowerBuilder 5. I have a sample pbl called serial.pbl I had gotten from Powersoft years ago. It uses 16-bit DLLs function from USER.EXE (OpenComm(), ReadCom(), WriteCom(), etc..) but these are no longer available in 32-bit paltforms (WIN95 or NT) It works like a charm in 16-bit. According to what I have researched so far, it seems that the only way to open a COM port is by using CreateFile() "API function from kernel32.dll" (as well as ReadFile(), WriteFile() ) Some of the arguments in Cre...

Open Ports
How can i find out what ports are currently opened?? there are many free products that will allow you to do a portscan on your server. Try to just make a search in google for "port scan software" and you will have plenty of choice. -- Cat Novell Support Connection Volunteer Sysop I thought that was configurable with BorderManager. In my case, a secured internet application needs Port "XXXX" to be opened on our network for inbound & outbound traffic. Is there a way from within BorderManager to confirm this?? Thanks, in advance.......

Web resources about - Determining if a Port is Open - SNMP Indy - embarcadero.delphi.winsock

Rate-determining step - Wikipedia, the free encyclopedia
... kinetics , the rate (or velocity) of a reaction mechanism with several steps is often determined by the slowest step, known as the rate-determining ...

Determining Business Value
... What I will attempt to do in this blog is provide a model for looking at business value focusing on the portfolio [...] The post Determining ...

Determining Sea Level
It’s much more complicated than you think:


Mac notebooks: Determining battery cycle count
For computers with Mac OS X v10.4.x or later, use the steps in this article to determine the cycles on your Mac notebook's battery.

Determining Valuation Multiples
Last week on MBA Mondays , I talked about valuing an internet marketplace business . In that post, I talked about using 1x gross marketplace ...

Determining a Player's True UZR
Question: How do I determines a player's real/predicted UZR including age adjustments? Why I asked the question: I needed a way for my Manger's ...

NBA Preseason Determining Destinies for Houston Rockets Bench
HOUSTON—It’s the night of Oct. 13, 2014, and the Houston Rockets are hosting the Phoenix Suns . Dwight Howard and James Harden are sitting this ...

It's Breyer and not O'Connor determining the outcome in the Ten Commandments monument case.
All eyes turn to Justice Breyer, who voted with the Chief Justice and Justices Kennedy, Scalia, and Thomas , to produce a victory for the state ...

DETERMINING IF WE NEED ANOTHER BUSH AS PRESIDENT: Using the Common Core Method
... invested by dousing it in gasoline and then applying a lit sparkler. Best, Doug For the rest of America, there's this: MT @darmercurio: Determining ...

Resources last updated: 1/8/2016 6:31:34 PM