IP of a router

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hsn
    New Member
    • Sep 2007
    • 237

    #1

    IP of a router

    hello everyone
    i working on a system and i need to get the IP address o a router by using java.
    the problem is whenever i create a program it gives me the IP address of my PC . by using a getlocalhost function.

    thanks for reading my question

    regards hsn
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by hsn
    hello everyone
    i working on a system and i need to get the IP address o a router by using java.
    the problem is whenever i create a program it gives me the IP address of my PC . by using a getlocalhost function.

    thanks for reading my question

    regards hsn
    Do you mean the IP with which your router has connected to the internet? If so, the only option I can think of right now is with a client-server-solution, where the server tells you, what IP you're connecting from... Or of course, your router can tell you itself in some way. What kind of router are you using? Can you run programs on it?

    Greetings,
    Nepomuk

    Comment

    • pronerd
      Recognized Expert Contributor
      • Nov 2006
      • 392

      #3
      If this is a web application, and if it is being accessed though a public domain, you could have it send a request to it self. Then you can get the external IP address from the HTTP headers. This will only work if the request you send goes outside your network to be resolved.

      Originally posted by hsn
      whenever i create a program it gives me the IP address of my PC . by using a getlocalhost function.
      That is what it should do. The getlocalhost() method as the name suggests gets the local host info.

      Comment

      • hsn
        New Member
        • Sep 2007
        • 237

        #4
        take it like this there is only one PC and it is connected to a router. there is no internet connection.

        thanks

        Comment

        • hsn
          New Member
          • Sep 2007
          • 237

          #5
          the IP address which i require is the local gateway address

          Comment

          • pronerd
            Recognized Expert Contributor
            • Nov 2006
            • 392

            #6
            Originally posted by hsn
            there is no internet connection.
            There does not need to be. You can run a server without an internet connection.

            The bottom line here is that the information you are looking for does not exist on the PC you are running your Java app on. So there is no way for the JRE to know what you want.

            I am assuming that router must be connected to something else other than a single PC. If not then it does not matter what IP is assigned since there would be nothing else to connect to.

            Comment

            • pronerd
              Recognized Expert Contributor
              • Nov 2006
              • 392

              #7
              Originally posted by hsn
              the IP address which i require is the local gateway address
              Of the router or the PC? What are you trying to use the gateway IP for? The whole point of Java is to not have to be tied that closely to the hardware you are running on.

              Comment

              Working...