java小程序取得IP地址
//文件名为NetTool.java(注意:在JAVA语言中大小写敏感)importjava.net.*;publicclassNetTool{InetAddressmy...
// 文件名为 NetTool.java (注意:在JAVA 语言中大小写敏感)
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main( String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("Your host IP is: "
+ mytool.getMyIP());
System.out.println("The Server IP is :"
+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
NetTool mytool;
mytool=new NetTool(); 这个是什么意思 NetTool mytool; 展开
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main( String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("Your host IP is: "
+ mytool.getMyIP());
System.out.println("The Server IP is :"
+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
}
}
NetTool mytool;
mytool=new NetTool(); 这个是什么意思 NetTool mytool; 展开
若以下回答无法解决问题,邀请你更新回答
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询