Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

How to find out own IP address

Discussion in 'Multiplayer' started by nafonso, Jan 29, 2008.

  1. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Isn't there a way to know what is my IP address?

    This would be specially helpful for direct ip connections, where the server machine creates a server that displays his IP address and Port, and he could then tell it to someone via MSN or whatever and he would connect.

    Regards,
    Afonso
     
  2. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,782
    there are several websites that display all sorts of information about your connection and among others your ip address, like http://www.ip-adress.com/. Or do you mean from inside Unity?
     
  3. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Inside Unity, of course. I think that something like Network.addresses with all of your ip address would be handy. Am I the only one thinking this?
     
  4. jeffcraighead

    jeffcraighead

    Joined:
    Nov 15, 2006
    Posts:
    740
    I agree, I was looking for this the other day as well. Would be handy just to put up on the GUI to tell others on the LAN/'Net. I ended up using the following code with a WWW class as a coroutine.

    Code (csharp):
    1.  
    2.  
    3. function CheckIP(){
    4.     myExtIPWWW = WWW("http://checkip.dyndns.org");
    5.     if(myExtIPWWW==null) return;
    6.     yield myExtIPWWW;
    7.     myExtIP=myExtIPWWW.data;
    8.     myExtIP=myExtIP.Substring(myExtIP.IndexOf(":")+1);
    9.     myExtIP=myExtIP.Substring(0,myExtIP.IndexOf("<"));
    10.     // print(myExtIP);
    11. }
    12.  
    13.  
     
    huyakinemota likes this.
  5. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
  6. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Thanks, the post was before 2.0.2, which introduced Network.player :wink: Now, besides one odd problem when we connect to the facilitator with a specific modem configuration, and the endian issue on PPC with externalIP being reversed, both of which larus, already knows, it works just fine. :)
     
    risokncn likes this.
  7. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    that's ok I figured you would have figured it out. i just posted a solution for others in the future if they ever search on that topic. :wink:

    Cheers.
     
  8. reth

    reth

    Joined:
    Jan 31, 2013
    Posts:
    2
    Hi,
    Many free online sites provide these services.I use Ip-details.com for my site. It is reliable and also fast. You can also have Your Viewers IP Address, and IP Address details(country, ISP, address, etc.) displayed on your website by just copying the code from this site on your webpage.
     
  9. BPPHarv

    BPPHarv

    Joined:
    Jun 9, 2012
    Posts:
    318
    Gotta love it when your first post is a 4 year old necro.
     
    Dudledok likes this.
  10. RamanThediyaSeet

    RamanThediyaSeet

    Joined:
    Mar 20, 2013
    Posts:
    1

    I will help you...
     
  11. FatalNickle

    FatalNickle

    Joined:
    Jul 27, 2009
    Posts:
    37
    You can also just go to google and type What is my IP and it'll tell you at the top of the page :)
     
  12. risokncn

    risokncn

    Joined:
    Oct 14, 2013
    Posts:
    20
  13. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    NetworkTransport.GetConnectionInfo will return ip and port of peer connected to you, than you can use or send this information...
    The reason why we not report local address is:
    (1) you can be natted
    (2) you can belong more than one lan...
     
  14. risokncn

    risokncn

    Joined:
    Oct 14, 2013
    Posts:
    20
    Thanks for a prompt reply,
    I am trying to get a list of available hosts in local network (while ignoring myself), I am using LLAPI broadcasting as you have explained here: http://forum.unity3d.com/threads/ho...ry-with-networktransport.323525/#post-2099741
    Since one device can be sender and receiver at the same time, it may receive its own broadcasts. I wanted to ignore these (in order to prevent devices from trying to connect to themselves) by checking if the IP of broadcasting source is one of my device's IPs. If this is not possible, then the only trick that comes to my mind is to include MAC in the bradcast message and check this instead. Or is there any better way to check if a received broadcast message is coming from my own device?
     
    Last edited: Jul 24, 2015
  15. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    I would say random 32 (64 or guid) value will be enough (and more simple). But if you are still worrying after connect you can send additional message to prevent auto-connect
    make sense?
     
    Bleggaman and risokncn like this.