不足之处,各位指点.偶在学习中.............
import java.net.*;
import java.io.*;
public class _0001GetIP
{
InetAddress myIPaddress=null;
InetAddress myServer=null;
String s;
BufferedReader bin;
public static void main( String args[])
{
_0001GetIP mytool=new _0001GetIP();
System.out.println("Your host IP is: " + mytool.getMyIP());
System.out.println();
System.out.println("The Server IP is :" +mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try
{
myIPaddress=InetAddress.getLocalHost();
}
catch (UnknownHostException e)
{
System.out.println("error occured");}
return myIPaddress;
}
//取得 的IP
public InetAddress getServerIP()
{
try
{
System.out.print("Enter your DNS:");
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader bin=new BufferedReader(in);
s=bin.readLine();
myServer=InetAddress.getByName(s);
}
catch (Exception e)
{
e.printStackTrace();
}
return myServer;
}
}
阅读(1358) | 评论(0) | 转发(0) |