List of usage examples for java.net InetAddress getHostAddress
public String getHostAddress()
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress addr = InetAddress.getByName("www.google.com"); System.out.println(addr.getHostAddress()); }
From source file:Main.java
public static void main(String[] args) { try {//ww w. ja va 2 s . c o m InetAddress me = InetAddress.getLocalHost(); String dottedQuad = me.getHostAddress(); System.out.println("My address is " + dottedQuad); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { try {/*from ww w . j a va 2s.c o m*/ InetAddress me = InetAddress.getLocalHost(); String dottedQuad = me.getHostAddress(); System.out.println("My address is " + dottedQuad); } catch (UnknownHostException e) { System.out.println("I'm sorry. I don't know my own address."); } }
From source file:Main.java
public static void main(String[] args) throws Exception { InetAddress ip = InetAddress.getLocalHost(); System.out.println("Current IP address : " + ip.getHostAddress()); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); System.out.print("Current MAC address : "); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); }//from w ww. j a v a 2 s . c om System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { ServerSocket server = new ServerSocket(8123); while (true) { Socket sock = server.accept(); InetAddress addr = sock.getInetAddress(); System.out.println("Connection made to " + addr.getHostName() + " (" + addr.getHostAddress() + ")"); Thread.sleep(5000);//from ww w. ja v a 2 s.co m sock.close(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress address = InetAddress.getLoopbackAddress(); System.out.println("Name: " + address.getHostName()); System.out.println("Addr: " + address.getHostAddress()); System.out.println(address.isLoopbackAddress()); }
From source file:SocketDemo.java
public static void main(String[] args) { try {//ww w. j a v a 2 s.c o m ServerSocket server = new ServerSocket(6123); while (true) { System.out.println("Listening"); Socket sock = server.accept(); InetAddress addr = sock.getInetAddress(); System.out.println("Connection made to " + addr.getHostName() + " (" + addr.getHostAddress() + ")"); pause(5000); sock.close(); } } catch (IOException e) { System.out.println("Exception detected: " + e); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress address = InetAddress.getByName("web.mit.edu"); System.out.println("Name: " + address.getHostName()); System.out.println("Addr: " + address.getHostAddress()); System.out.println(address.isMCLinkLocal()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress address = InetAddress.getByName("web.mit.edu"); System.out.println("Name: " + address.getHostName()); System.out.println("Addr: " + address.getHostAddress()); System.out.println("Reach: " + address.isReachable(3000)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress address = InetAddress.getByName("web.mit.edu"); System.out.println("Name: " + address.getHostName()); System.out.println("Addr: " + address.getHostAddress()); System.out.println(address.isMCNodeLocal()); }