Results 1 to 3 of 3

Thread: Get Ip adress?

  1. #1
    Godsent is offline Member
    Join Date
    Apr 2009
    Posts
    6
    Rep Power
    0

    Default Get Ip adress?

    Is where any way to get IP address the same you can look at at websites like ipchicken.com or whatismyip.com ?

    I tried many tutorials and all of them obtain Default Gateway. Anyone can help me?

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    The IP address you get from whatismyip will be the external IP address of your router or equivalent, which has a separate IP address for your local network side. Only external servers can see the external IP, while you can only see the local IP. Try connecting a socket to an external server and asking what your IP is.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    lipun4u is offline Member
    Join Date
    Jul 2009
    Location
    bhubaneswar
    Posts
    5
    Rep Power
    0

    Default

    If u want to know ur own ip address ..the following code may help u...


    import java.util.*;
    import java.net.*;
    import java.net.NetworkInterface;

    public class InetAssressExample {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
    if (interfaceList == null)
    System.out.println("Error");
    else {
    while(interfaceList.hasMoreElements()) {
    NetworkInterface iface = interfaceList.nextElement();
    System.out.println("Interface : " + iface.getName() + " :: ");
    Enumeration<InetAddress> addrList = iface.getInetAddresses();
    if(!addrList.hasMoreElements()) {
    System.out.println("\t(No address for this interface");
    }
    while(addrList.hasMoreElements()) {
    InetAddress address = addrList.nextElement();
    System.out.println("\tAddress " + ((address instanceof Inet4Address ? "(v4)"
    : (address instanceof Inet6Address ? "(v6)" : "(?)"))));
    System.out.println(": " + address.getHostAddress());
    }

    }
    }
    }catch(SocketException se) {
    System.out.println("Error getting network interfaces : " + se.getMessage());
    }

    }

    }

Posting Permissions

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