#1
June 22nd, 2016, 11:05 AM
| |||
| |||
Get IP Address In Java
I work with java a now I want to get the IP address of my computer using the Java application so can you please tell me that what code should I follow
|
#2
June 22nd, 2016, 11:24 AM
| |||
| |||
Re: Get IP Address In Java
hey the IP address of host computer can be achived by the InetAddress class. You can do it by calling getByName() method with host name as parameter, it returns InetAddress object. On this object you can call getHostAddress() method to get the IP address of the given host. Java Code package com.myjava.ip; import java.net.InetAddress; import java.net.UnknownHostException; public class MyIpByHost { public static void main(String a[]){ try { InetAddress host = InetAddress.getByName("www.java2novice.com"); System.out.println(host.getHostAddress()); } catch (UnknownHostException ex) { ex.printStackTrace(); } } } If you want more details then feel free to contact again |
|