java f00lz

Discussion in 'OT Technology' started by johnnywallywallace, Dec 12, 2003.

  1. so I want to grab the IP address of the host a small app is running on. only problem is, I don't see how one specifies WHICH ethernet interface, if you're running multiple interfaces ... I see where I can grab my hostname then get all IPs by hostname, I suppose I could then ignore all 192. and 10. addresses to determine my external IP, but I'd have to think there'd be a smarter solution ...
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
  3. ph1

    ph1 Guest

    use java.net.NetworkInterface.getNetworkInterfaces() to get an enumeration of all interfaces on the host, then for each interface in the enum get the InetAddresses using
    getInetAddresses()

    how to determine what you think is a valid address is up to you.
     
  4. so it sounds like, like I said, I have to grab all and rule out those I know to be internal ... there's no better way than full enumeration? there's no way to specify getNetworkInterface("eth0") or something handy and direct like that?
     
  5. CompiledMonkey

    CompiledMonkey New Member

    Joined:
    Oct 26, 2001
    Messages:
    8,528
    Likes Received:
    0
    Location:
    Richmond, VA
    Check the APIs. There certainly could be something like that.
     
  6. aphoric

    aphoric Even if god did exist, it would be necessary to ab

    Joined:
    Aug 29, 2003
    Messages:
    918
    Likes Received:
    0
    Location:
    Leaving Afghanistan
    What he said...

    getNetworkInterfaces

    public static Enumeration getNetworkInterfaces()
    throws SocketException
    Returns all the interfaces on this machine. Returns null if no network interfaces could be found on this machine. NOTE: can use getNetworkInterfaces()+getInetAddresses() to obtain all IP addresses for this node

    Returns:
    an Enumeration of NetworkInterfaces found on this machine
    Throws:
    SocketException - if an I/O error occurs.

    And about detirmining the real address, you could start by eliminating all the ones that are in the 192.168.0.255 subnet...

    But, if they are using a router, the real IP is not going to be on their machine at all..
     
  7. hehe thanks for repeating what I said intially :p I have to get all, as I already knew, and rule out my internals, as I planned. :fawk:

    but thanks for the input.
     

Share This Page