List of usage examples for java.net InetAddress getHostName
public String getHostName()
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.isAnyLocalAddress()); }
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.isMCGlobal()); }
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(NetworkInterface.getByIndex(0), 0, 3000)); }
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 w ww. j a va 2s .com sock.close(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w. j ava 2 s. c o m*/ InetAddress address = InetAddress.getLocalHost(); System.out.println("My name is " + address.getHostName()); } catch (UnknownHostException e) { System.out.println("I'm sorry. I don't know my own name."); } }
From source file:SocketDemo.java
public static void main(String[] args) { try {//from w ww . j a va 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 addr = InetAddress.getLocalHost(); // Get IP Address byte[] ipAddr = addr.getAddress(); // Get hostname String hostname = addr.getHostName(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { InetAddress addr = InetAddress.getByName("127.0.0.1"); byte[] ipAddr = new byte[] { 127, 0, 0, 1 }; addr = InetAddress.getByAddress(ipAddr); // Get the host name String hostname = addr.getHostName(); // Get canonical host name String canonicalhostname = addr.getCanonicalHostName(); }
From source file:GetIP.java
public static void main(String[] args) { InetAddress address = null; try {// ww w. j a v a2s. com address = InetAddress.getByName("www.java2s.com"); } catch (UnknownHostException e) { System.exit(2); } System.out.println(address.getHostName() + "=" + address.getHostAddress()); System.exit(0); }
From source file:Main.java
public static void main(String[] args) throws Exception { InetAddress address = null; if (args.length == 0) { System.out.println("usage: GetIP host"); System.exit(1);//from w ww.j a v a2s . c om } address = InetAddress.getByName(args[0]); System.out.println(address.getHostName() + "=" + address.getHostAddress()); System.exit(0); }