Thursday, December 12, 2013

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;
 
 }
 
   }