locked
How to find the IP address of the devices on a local network? RRS feed

  • Question

  • Hi,

    I have a need in my application to list all the IP addresses of the devices connected to the local network of the computer running the application.

    Thanks,

    EitanB

    Friday, January 11, 2013 3:06 AM

Answers

  • @morten: you are right morten, got carried away by the title of the thread.

    @eitanbarazani: So the answer is, "no", you cannot discover the devices in the network.... you can try pinging each IP in the subnet (e.g. 192.168.1.*) but I guess this wouldn't be a desirable solution.


    Can Bilgin
    Blog CompuSight

    Tuesday, January 15, 2013 7:51 AM
  • How is this discovering what devices there are on the network? I assume you want to be able to discover all the PCs on the network, so you won't know the network host names up front.

    /Morten
    twitter: http://www.twitter.com/dotMorten
    blog: http://www.sharpgis.net

    Monday, January 14, 2013 7:50 PM

All replies

  • Usually you would use "NetApi32" but it doesn't look like you have access to this from a Windows Store App. I could also see how that could be a security issue and why that is then blocked from the store apps. I definitely don't see anything in the network api's either: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/br211377.aspx

    /Morten
    twitter: http://www.twitter.com/dotMorten
    blog: http://www.sharpgis.net

    Friday, January 11, 2013 5:26 AM
  • Hi,

    Maybe you can try this API NetworkInformation.GetHostNames. You can follow this thread to use it
    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/e9c3a808-6b29-4885-964d-0c961e8ac65d/

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 14, 2013 7:25 AM
  • yeap you need to open a connection and get the IP address... this can be a stream socket or a UDP socket connection:

    HostName serverHost = new HostName("www.bing.com");
    
    var clientSocket = new Windows.Networking.Sockets.StreamSocket();
    
    // Try to connect to the remote host
    await clientSocket.ConnectAsync(serverHost, "http");
    
    // Get the HostName as DisplayName, CanonicalName, Raw with the IpAddress.
    var ipAddress = clientSocket.Information.RemoteAddress.DisplayName;

    or

    IReadOnlyList<EndpointPair> data = await DatagramSocket.GetEndpointPairsAsync(new HostName(remoteHostName), "0");
    
    EndpointPair p = data[0];
    
    var ipAddress = p.RemoteHostName.DisplayName; 
    

    hope it helps..


    Can Bilgin
    Blog CompuSight

    Monday, January 14, 2013 11:55 AM
  • How is this discovering what devices there are on the network? I assume you want to be able to discover all the PCs on the network, so you won't know the network host names up front.

    /Morten
    twitter: http://www.twitter.com/dotMorten
    blog: http://www.sharpgis.net

    Monday, January 14, 2013 7:50 PM
  • @morten: you are right morten, got carried away by the title of the thread.

    @eitanbarazani: So the answer is, "no", you cannot discover the devices in the network.... you can try pinging each IP in the subnet (e.g. 192.168.1.*) but I guess this wouldn't be a desirable solution.


    Can Bilgin
    Blog CompuSight

    Tuesday, January 15, 2013 7:51 AM
  • Hi Can,

    Thanks for your answer!

    I implemented an IP text in.

    EitanB

    Monday, January 21, 2013 5:40 PM