C# Ping IP Address RRS feed

  • Question

  • string copyFiles;
                copyFiles = "\\\\" + ipAddress.Text;
                Ping ping = new Ping();
                PingReply reply = ping.Send(ipAddress.Text, 1000);
                if (reply.Status == IPStatus.Success)
                    this.statusMsg.Text = "Files were successfuly copied to users Desktop";
                    this.statusMsgFail.Text = "Failed, files were not copied";

    The script above works when the ip address is correct or not responding, i get a random error message if it is not either of them.  For example: if I enter a space "321351 " the sends me back an error message

    I get the following error message

    System.Net.NetworkInformation.PingException: 'An exception occurred during a Ping request.'

    SocketException: No such host is known


        PingReply reply = ping.Send(ipAddress.Text, 1000);

    • Edited by mcubac Tuesday, August 13, 2019 8:46 PM
    Tuesday, August 13, 2019 8:40 PM

All replies

  • Hi mucubac,

    Thank you for posting here.

    According to your description, you want to solve the exception you got when you enter a space "32151" to the textbox. Also, I get the same error with you.

    Based on my search, I find Ping.Send(String, Int32) method has some limit about the parameter '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.

    Therefore, you may meet the error when you use "321351 ".

    Hope my explanation could be helpful.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 14, 2019 1:42 AM