Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created June 9, 2011 14:38

Revisions

  1. freynaud created this gist Jun 9, 2011.
    24 changes: 24 additions & 0 deletions ip.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    public class IPTroubleShoot {

    public static void main(String[] args) {
    current();
    test();
    }

    public static void current() {
    InetAddress addr;
    try {
    addr = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
    throw new InstantiationError("cannot find hub ip");
    }
    String host = addr.getHostAddress();
    System.out.println("current : " + host);
    }

    public static void test() {
    NetworkUtils utils = new NetworkUtils();
    String s = utils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    System.out.println("test : " + s);
    }
    }