Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By kjkrum

Thread: How To Get The Actual Computer's IP Address

  1. #1
    ElvisMachuca is offline Member
    Join Date
    Jan 2013
    Posts
    32
    Rep Power
    0

    Default How To Get The Actual Computer's IP Address

    Hi,

    I wrote a Chess game that uses socket to connect to another computer, and allow player vs player and player vs computer game sessions.

    However, there is a problem which I noticed.

    When you get the IP address of the computer in which the program is running, you are not getting the computer's actual IP, you are getting the Router's IP.

    Is there a way to get around this.

    So the problem is that when I go to another computer, located in a different house or lets say from my school, the program cannot connect back to my home IP, because it uses the router's ip, not the computer's ip I am running the server program.

    Is there a way to get the Computer's IP, not the router's ip when summoning or invoking the get IP address method from the socket class?

    When I say that the socket class is acquiring the router's ip, well that's done without my interfering...I don't know why it does that, it is somehow recognizing the router and not the computer.

    The thing is that the server program is written that any client program is able to connect to the home server.

    But when I run the program from a different location other than the current home, the sockets don't connect because it is somehow recognizing the router's ip not the computer's ip.

    help.

  2. #2
    ElvisMachuca is offline Member
    Join Date
    Jan 2013
    Posts
    32
    Rep Power
    0

    Default Re: How To Get The Actual Computer's IP Address

    No I cannot provide a copy of the program...

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How To Get The Actual Computer's IP Address

    This really has nothing to do with Java. If your server is behind a router, you need to configure the router to forward incoming connections to your internal IP address. To find out what the external address is, you'll probably have to connect to something that reports what it sees as your address, such as What Is My IP | Shows Your IP Address..
    SurfMan likes this.
    Get in the habit of using standard Java naming conventions!

  4. #4
    BinaryDigit09 is offline Member
    Join Date
    May 2012
    Posts
    18
    Rep Power
    0

    Default Re: How To Get The Actual Computer's IP Address

    The only way I know to get your external IP in Java is connect to What Is My IP | The IP Address Experts Since 1999 and parse it from the HTTP GET result. Short of that, I would add a dialog that asks.

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    902
    Rep Power
    2

    Default Re: How To Get The Actual Computer's IP Address

    The computer's internal IP is useless to you if you're connecting to it from teh interwebz. Let's say my network is 10.0.0.0/24 and yours is 10.0.0.0/24 as well. When I would know your computer is 10.0.0.102, what do you think would happen when I try to connect to 10.0.0.102? Correct, it would loop in my own network, bombing out because the program is not running there. Even, when the other network is in the 192.168.0.0 range, these are not even routed over the internet. Internal IP's are only interesting... internally...
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: How To Get The Actual Computer's IP Address

    I don't believe that is what they are talking about. They want the ISP address that front's their local router. Which would be different than any local private IP address.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    902
    Rep Power
    2

    Default Re: How To Get The Actual Computer's IP Address

    Quote Originally Posted by jim829 View Post
    I don't believe that is what they are talking about. They want the ISP address that front's their local router. Which would be different than any local private IP address.

    Regards,
    Jim
    True dat. If he has the server running in his basement, and he wants to connect to it, his router needs portforwarding configured like kjkrum said in post #3. You can't "find it out", you either have to remember the IP address, or get yourself a nice and shiny new domainname playchessathome.com and let that point to your home router's IP (Unless it's not static ofcourse, then it would be useless...).
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,340
    Rep Power
    5

    Default Re: How To Get The Actual Computer's IP Address

    If you want to be able to connect to your home computer from anywhere on the internet, I suggest you get a free FQDN from dyndns.org. You get two hostnames of your choice using one of their free domain names. Most home routers allow you to configure a dynamic dns service with the userid and password provided when you register. Since these are typically not static addresses, the DNS service time out is 60 seconds. Your router needs to be configured to periodically update your status. The router will/should also update your status if your ISP changes IP addresses on you. If you want to access more than one PC then you will need to configure port forwarding. Check out the other details and services at Managed DNS | Outsourced DNS | Anycast DNS. I have been using this service for over a decade. And I still have my originally chosen hostname. All for free!

    Only 3 months late, but maybe it will help someone else.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Formal and actual parameters
    By Stud1 in forum New To Java
    Replies: 6
    Last Post: 01-12-2014, 02:19 AM
  2. Actual Storage
    By java software in forum Java Software
    Replies: 0
    Last Post: 10-08-2011, 05:39 PM
  3. copy actual window to clipboard
    By greenhorn in forum New To Java
    Replies: 10
    Last Post: 04-01-2011, 02:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •