check udp socket

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
blacksun
Forum Newbie
Posts: 4
Joined: Fri Apr 21, 2006 9:02 am

check udp socket

Post by blacksun »

I want to check if SNMP on (port 161) is running on a remote host.

SNMP uses UDP and I know that you should send data to UDP in order to know if the the service is
running

Consider the code :

Code: Select all

/*Check UPD protocol : services NTP , NFS, SNMP*/
function checkPortUDP($host,$port,$timeout = 2){
    $fp = @fsockopen("udp://".$host, $port, $errno, $errstr, $timeout);
	    if (!$fp) return false;
		else return false;
}//end function
How do I check if SNMP is running?
Last edited by blacksun on Fri Apr 21, 2006 9:22 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Help with what?
blacksun
Forum Newbie
Posts: 4
Joined: Fri Apr 21, 2006 9:02 am

Post by blacksun »

how do i check if the udp port is running snmpd?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

talk some snmp to it? :p (Btw, there is an snmp extension)
blacksun
Forum Newbie
Posts: 4
Joined: Fri Apr 21, 2006 9:02 am

Post by blacksun »

i already have that in my application; before I talk SNMP;
i want to check the UDP ports for (SNMP, NTP etc).

how do i check if the UDP port is up?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You have to talk SNMP to it. There's no way around that as the socket may open without knowing if the connection failed or not.
blacksun
Forum Newbie
Posts: 4
Joined: Fri Apr 21, 2006 9:02 am

Post by blacksun »

ok; i see.
Post Reply