简体   繁体   中英

How to check whether IP address is reachable or not using C#

I am validating whether the given IP is reachable or not. In server PING, TELNET, etc options are disabled. I tried with Socket Connection but this needs the given PORT to be allowed.

Is there any reliable solution to check this. It should work on all the environment [independent of OS]

Please guide me to implement this on C#

There is no such thing as "IP address is reachable" in general. Relevant is, if a specific service on a server can be successfully contacted - because at the end one wants to use the server for a specific purpose. Checking if one can ping the server says nothing about this: it might be that ping is disabled or blocked but that the server can still be reached by HTTP (ie web). Similar it might be that ping works but HTTP will not work either because there is no HTTP service running at the server or because some firewall in between is blocking access to HTTP for all or even only for specific clients.

Thus, you have to decide what you really want to know, ie what you want to achieve with the knowledge of the IP being reachable. For example if you want to use this knowledge to access the web server there later you should try a connection at port 80 (default port for HTTP).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM