Click here to Skip to main content
13,400,969 members (37,755 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 16 Sep 2011

How to Ping Network IP or Hostname using Silverlight?

, 16 Sep 2011
Rate this:
Please Sign up or sign in to vote.
Pinging a network IP or Hostname is not available in Silverlight. But you can do this using WCF service. In this post, I am going to implement the same thing for you.


Pinging a network IP or Hostname is not available in Silverlight. But you can do this using WCF service. In this post, I am going to implement the same thing for you. I am using Silverlight 4 here. But this can also be possible in Silverlight 3.

Code of Use

Create a Silverlight application with Silverlight hosting website as “ASP.NET Web Site”:


Now this will create an XAML page for you by default. Add one TextBox and one Button into it. We will use TextBox to enter IP Address or the Hostname and on click of the Button, it will ping that entered IP or Hostname. As a limitation to the Silverlight, you can’t ping directly from the client application. You need to create a WCF service and using that, you can easily ping. Remember there are some limitations here too as you are pinging it from the WCF hosting server.

Let’s implement our WCF service. Create a service method named PingNetwork and pass the hostNameOrAddress as a string. This will be your IP address or the host’s DNS name. Then create an instance of System.Net.NetworkInformation.Ping and pass the required parameter to its “Send” method. This will return you “PingReply”. Now check the Status of the reply. There are several options available. I used only IPStatus.Success to check it and depending upon that, returning true or false.

public bool PingNetwork(string hostNameOrAddress)
    bool pingStatus = false;

    using (Ping p = new Ping())
        string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
        byte[] buffer = Encoding.ASCII.GetBytes(data);
        int timeout = 120;

            PingReply reply = p.Send(hostNameOrAddress, timeout, buffer);
            pingStatus = (reply.Status == IPStatus.Success);
        catch (Exception)
            pingStatus = false;

    return pingStatus;

Now come to the client side implementation. Add the service reference to the Silverlight application and then call the service method with your IP Address or the DNS name of the host:


As it is an asynchronous call, implement the “Completed” event for the method. In the completed event, check the e.Result value. If the server is able to ping, it will return true and in other case, it will return false.

This is a simple implementation of the logic. As told earlier, this will ping from server and not from the client.


  • 16th September, 2011: Initial post


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


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...


Comments and Discussions

GeneralMy vote of 4 Pin
Daniyal Ahmad Rizwan13-Sep-14 7:17
memberDaniyal Ahmad Rizwan13-Sep-14 7:17 
QuestionGood Pin
Arun Jacob26-Sep-11 22:08
memberArun Jacob26-Sep-11 22:08 
AnswerRe: Good Pin
_ Kunal Chowdhury _26-Sep-11 23:29
mvp_ Kunal Chowdhury _26-Sep-11 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180218.2 | Last Updated 16 Sep 2011
Article Copyright 2011 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid