Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to ping a IP address with button click event in asp.net page and if ping is successful then redirect to that IP address(of a URL)
Example of IP address: http://xxx.xxx.xxx.xx/sample
Posted
Updated 4-Aug-16 23:15pm

 
Share this answer
 
Get ping result by it's status
See the codes are following below
protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Ping ping = new Ping();
            PingReply pingresult = ping.Send("81.2.199.57");
            if (pingresult.Status.ToString() == "Success")
            {
                Response.Redirect("http://xxx.xxx.xxx.xx/sample");
            }
        }
 
Share this answer
 
http://stackoverflow.com/questions/11800958/using-ping-in-c-sharp
 
Share this answer
 
use Ping.Send Method (IPAddress) Method

This method sends to the host that is specified by address a 32 Byte data buffer with the ICMP echo message. The method waits five seconds for an ICMP echo reply message. If it does not receive a reply in that time, the method returns and the Status property is set to TimedOut.



Ping.Send Method (String)

SQL
public PingReply Send(
    string hostNameOrAddress
)


Parameters
hostNameOrAddress
Type: System.String
A String that identifies the computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.
 
Share this answer
 
[^]<small></small>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900