Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Get All IP devices on the same Network

Discussion in 'Scripting' started by Deedlithh, Dec 21, 2015.

  1. Deedlithh

    Deedlithh

    Joined:
    Dec 21, 2015
    Posts:
    8
    Hi , i want to connect to my LAN and return all devices connected on this LAN.
    For examples, I need to detect all PS4, Xbox ONE connected on the same Network as mine with my android device when i click on button called "Check Devices " :)

    For now , i just have my computer's IP :/

    Thx for helping me,
    Sincerly,
    Cindy
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    If the Consoles are "cooperative" you can just ping them , then you know that there is a device at all.
    Just ping all possible addresses from your subnet.
     
  3. Deedlithh

    Deedlithh

    Joined:
    Dec 21, 2015
    Posts:
    8
    when i want to ping console's Ip, it's not working :/
    My PS4 ip is : 192.168.1.129

    if i use :
    System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
    PingReply rep = p.Send("192.168.1.129");

    i have socket Error

    and if i use :
    System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
    p.PingCompleted += new PingCompletedEventHandler(p_PingCompleted);
    p.SendAsync("192.168.1.129", 100);
    it doesn't respond.

    thx
     
  4. Deedlithh

    Deedlithh

    Joined:
    Dec 21, 2015
    Posts:
    8
    I find why socket error, it's because i need to open Unity as Administrator.
    If the status is success, can i have the name of the device which Ip correponding ?
     
  5. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    For the device name you would need to to run a equivalent of the windows command NSLOOKUP to "look up" the name of the device provided by the nearest name server. If you are trying to run it on android you are probably best of trying to make a small native plugin that does that for you since .net does not bring a nice integrated function for that.
    Maybe there is a better way like some kind of prot that the console will respond on but i do not have any of those consoles and i'm not familiar with their behavior.
     
  6. Deedlithh

    Deedlithh

    Joined:
    Dec 21, 2015
    Posts:
    8
    yes i want to run it on Android device and after on IOS device :)
    i need to get all PS4 and XboxOne connected on the same LAN, and after that i choose one in the list to connect my phone to the console that i selected :)
     
  7. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    It sounds like you have a application running on the console, is that correct?
    If yes you could be listening on a specific network port for a signal from your mobile app. If the console detects the signal on that specific port that you can send via broadcast out from your mobile device, the console can answer back to the mobile device. ( that is the theory , i'm not sure if you can open ports for listening on the mobile platforms or the consoles)
     
  8. Deedlithh

    Deedlithh

    Joined:
    Dec 21, 2015
    Posts:
    8
    yes it's for an application on the console. i need to connect my phone to my console for using it as a mic :)
    i will check if i can listen specific port on the console for detecting it from my phone.