2023 2024 EduVark > Education Discussion > General Discussion


  #1  
June 22nd, 2016, 11:05 AM
Unregistered
Guest User
 
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
Similar Threads
Thread
VTU Java Lab Programs
Java dce rpc
JAVA Jobs in HCL
CMC Ltd Java
Java Certification
Java Certification Fee
Java Training NJ
MBA Java
Online Course For Java
Online Java Course
Java Programmer
Jmeter Java
Vtu java syllabus
Java Certification
Details of difference between Core Java and Advanced Java

  #2  
June 22nd, 2016, 11:24 AM
Super Moderator
 
Join Date: Mar 2012
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


Quick Reply
Your Username: Click here to log in

Message:
Options



All times are GMT +5. The time now is 08:43 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.6.0

1 2 3 4 5 6 7 8