如何将ip地址作为输入提供给java ...如果我将ip addrees作为输入需要显示服务器中是否存在 [英] How to give ip address as a input on java...if I give ip addrees as a input need to display present in the server or not
本文介绍了如何将ip地址作为输入提供给java ...如果我将ip addrees作为输入需要显示服务器中是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
how to give ip address as a input on java...if i give ip addrees as a input need to display present in the server or not
我尝试了什么:
What I have tried:
public class CrunchifyGetIPHostname {
public static void main(String[] args) {
InetAddress ip;
String hostname;
try {
ip = InetAddress.getLocalHost();
hostname = ip.getHostName();
System.out.println("Your current IP address : " + ip);
System.out.println("Your current Hostname : " + hostname);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
推荐答案
目前还不是很清楚你最终想做什么但 InetAddress(Java Platform SE 7) [ ^ ]类提供所有必要的功能。
未经测试的例子:
It is not quite clear what you finally want to do but the InetAddress (Java Platform SE 7 )[^] class provides all necessary functions.
Untested example:
// Input:
// strIp containing an IP address or a machine name
// strServer containing a machine name
// Get the IP address to look for as InetAddress
InetAddress ip = InetAddress.GetByName(strIp);
// Get all IP adresses associated with strServer
InetAddress[] serverIps = InetAddress.getAllByName(strServer);
for (int i = 0; i < serverIps.length; i++)
{
if (ip.equals(serverIps[i]))
{
// Is an IP address of the server
}
}
这篇关于如何将ip地址作为输入提供给java ...如果我将ip addrees作为输入需要显示服务器中是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文