public class NetTool
{
InetAddress myIPAddress = null;
InetAddress myServer = null;
public static void main(String[] args)
{
System.out.println(new NetTool().getMyIP());
System.out.println(new NetTool().getServerIP("www.csdn.net"));
}
public InetAddress getMyIP()
{
try
{
myIPAddress = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
LogManager.debugLog.debug("Caught an exception : ", e);
}
return this.myIPAddress;
}
public InetAddress getServerIP(String webUrl)
{
try
{
myServer = InetAddress.getByName(webUrl);
}
catch (Exception e)
{
LogManager.debugLog.debug("Caught an exception : ", e);
}
return myServer;
}
}
{
InetAddress myIPAddress = null;
InetAddress myServer = null;
public static void main(String[] args)
{
System.out.println(new NetTool().getMyIP());
System.out.println(new NetTool().getServerIP("www.csdn.net"));
}
public InetAddress getMyIP()
{
try
{
myIPAddress = InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
LogManager.debugLog.debug("Caught an exception : ", e);
}
return this.myIPAddress;
}
public InetAddress getServerIP(String webUrl)
{
try
{
myServer = InetAddress.getByName(webUrl);
}
catch (Exception e)
{
LogManager.debugLog.debug("Caught an exception : ", e);
}
return myServer;
}
}
URL.getHost();
InetAddress.getHostAddress()
import java.io.*;
public class TestAdress{
public static void main(String[] args) throws Exception{
System.out.println(InetAddress.getByName("www.csdn.net").getHostAddress()); }
}