Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

IP numbers

  Asked By: Lewis    Date: May 02    Category: Java    Views: 766
  

Is there a library function that lets me do:


int value = add_one_to_ip( "10.10.10.10" ) ;

System.out.print ( value );

gives : 10.10.10.11

Of course if the function can do impressive things with the subnet mask and
incrementing the network number when the highest ip is reached, that would be
useful.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Silk Choco     Answered On: Dec 03

Well 1 I use the following code snippet to get ip :

private String getIP()
{
// This try will give the Public IP Address of the Host.
try
{
URL url = new URL("http://automation.www.example.com/n09230945.asp");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String ipAddress = new String();
ipAddress = (in.readLine()).trim();

if (!(ipAddress.length() > 0))
{
try
{
InetAddress ip = InetAddress.getLocalHost();
System.out.println((ip.getHostAddress()).trim());
return ((ip.getHostAddress()).trim());
}
catch(Exception ex)
{
return "ERROR";
}
}
System.out.println("IP Address is : " + ipAddress);


External ip address can be obtained via http://www.ip-details.com/ too .

 
Didn't find what you were looking for? Find more on IP numbers Or get search suggestion and latest updates.




Tagged: