locked
Sending Ping Using Sockets

    Question

  • I am trying to figure out how to send a basic ping request to a target IP in C# for a Windows Store Apps. All I can find is that the standard Ping class in the .NET framework is not available for Windows Store Apps, and that the only way is to do it by implementing sockets.

    In researching socket classes in a Windows Store App, I can't seem to find one that support ICMP (ping), but only UDP or TCP.

    Is pinging a host a restriction for a Windows Store App?  If you can help guide me in the appropriate direction, please do so! :)

    Sean

    Wednesday, April 30, 2014 2:26 AM

All replies

  • First, what's the end goal in doing this?

    Second, are you writing an app that is intended to be sold in the store, or is it an LOB app?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 30, 2014 12:16 PM
    Moderator
  • Thanks for the reply Matt.  End goal is just to try writing an app for myself that can do some basic network tasks (ping, trace route, etc).  Of course starting with the basic Ping but already finding it difficult to figure out.  I already did a lot of it in straight C# in WPF project, and had no issues... but of course that was using the handy Ping class in System.Net.Networking namespace, which sadly doesn't exist in Windows Store Apps that I can see.

    I'm just learning how to do Windows Store App development now, especially with the new Universal App projects in Visual Studio.  So hoping to at least give myself my own personal app to do this first, then maybe if I develop it well submit to the app store as a free app to give to anybody else who might like to have it.

    Sean


    • Edited by S O'Connor Wednesday, April 30, 2014 12:22 PM
    Wednesday, April 30, 2014 12:21 PM
  • The point of my question is to figure out what your intent is, so we can provide correct workarounds.  An LOB app has far less restriction on using non-WinRT components than a Store-submitted app does, so it's worthwhile to ask about the end goal.

    If this is a learning app, then it would probably be better to work on something that has easier to use, built-in functionality, rather than trying to invent something that doesn't presently exist within the API.

    It can be done, but there's not a simple API for it at this time.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 30, 2014 2:11 PM
    Moderator
  • So in short the API to allow me to do this for a Windows Store app simply does not exist but can be done?

    Are you able to point me in a right direction on how I could start some form of implementation considering the API restriction?

    Wednesday, April 30, 2014 2:15 PM
  • So again, is it more important that you get this working for yourself, or for the end goal of distributing this in the Store?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, April 30, 2014 2:28 PM
    Moderator
  • End goal: distribution via Windows Store
    Wednesday, April 30, 2014 3:28 PM
  • I thought this was possible, but I don't see any networking APIs that allow you to send something over a raw socket.  None of the WinRT sockets seem good for this, and I don't see any WinSock APIs in the C++ set. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, May 01, 2014 3:12 PM
    Moderator
  • PM for the Windows Runtime Sockets API here; you are correct in that there's not an API for ICMP (Ping) in the store, and the APIs that you would need to call are blocked.

    The most common reason to use ping is to "see if a machine is up". But in modern networks, it's actually not super accurate to do this any more; tons of places have firewalls that block PING. 

    You can often get similar information by trying to open a socket on port 80; most machines have that port open nowadays.  And it's cool to test your home subnet and see how many boxes you have that include a mini-web server.


    Network Developer Experience Team (Microsoft)

    Thursday, May 01, 2014 6:15 PM
  • It's actually important if you literally want a network tool for a Surface RT to ping some device on your home (or friend's network) for troubleshooting.

    I guess I just don't understand why I can do this with Android apps, iOS apps, but it's blocked with WinRT/Windows Store Apps?  I thought Microsoft wanted developers to start making apps for their platforms not prevent them from doing what they want to do.

    Thursday, May 01, 2014 6:26 PM
  • Neither iOS nor Android (AFAIK) have a command prompt, do they?  You can Ping from the command prompt in Surface RT - nothing new there.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 02, 2014 5:42 PM
    Moderator