Get own IP address in JAVA

This is a code snippest to get the current IP address of own system.

code:

package com.oksbwn.systeminteraction;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class IpAdress{

//public static void main(String[] args){
public static InetAddress getIP(){
InetAddress ip;
try {ip = InetAddress.getLocalHost();
return ip;
} catch (UnknownHostException e) {e.printStackTrace();}
return null;

}

}

Catch Me On

Bikash Panda

Blogger / Embedded System Developer at WGLabz
A techie, tinkerer and tech lover, who loves to blog and feels everyone can learn tech provided they have the right attitude towards learning and passion. By profession, I am an IOT developer working in Smart Home/ Smart Grid domain.
Bikash Panda
Catch Me On

Latest posts by Bikash Panda (see all)

Related posts