network programming - Checking open UDP Port in C++ -
how can check if remote udp port open using native c++? since udp connection-less, calling connect() not helpful. cannot try binding since not local. nmap cannot indicate. (however netstat can find out, think looks internal information open ports/files). there anyway detect it? if go layer down on network level, possible send icmp message c++ check port-unreachable status? mean, give enough information on port status?
platform linux.
i assume trying determine whether or not udp port on remote machine being passed through firewall and/or has application running on it.
you cannot reliably determine this. closest can come try sending series of small datagrams address , port, spaced 1 second apart 10 seconds.
if there no firewalls blocking port , no application running, remote system might send icmp_unreach_port (port unreachable). if there no blocking firewalls , remote system down, router might send icmp_unreach_host or icmp_unreach_net. if firewall blocking you, might send icmp_unreach_filter_prohib, firewalls don't send anything.
the odds of getting of pretty slim because firewalls block sort of icmp feedback. if icmp message come back, linux not let see unless running root. operating systems report icmp errors failure of next sendto() same address/port, why need repeat message several times. not, in case must open specific icmp port , parse return messages.
even if somehow icmp message, understand not reliable. example, icmp_unreach_port though application not listening, actively sending data. (that's rare, i've seen happen.)
if application running on given port , if know application , if know how craft message cause application respond you, doing , getting response best indication port open. getting no response means nothing: maybe port blocked, maybe application not running, or maybe didn't message.
bottom line: no, not really.
Comments
Post a Comment