java中怎么获取客户端的真实的ip和端口号
1个回答
2016-08-08 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
public static String getHostIpAddress() {
String hostIp = "";
InetAddress netAddress = getInetAddress();
hostIp = getHostIp(netAddress);
return hostIp;
}
public static InetAddress getInetAddress() {
try {
return InetAddress.getLocalHost();
} catch (UnknownHostException e) {
System.out.println("unknown host!");
}
return null;
}
public static String getHostIp(InetAddress netAddress) {
if (null == netAddress) {
return null;
}
String ip = netAddress.getHostAddress(); // get the ip address
return ip;
}
public static String getHostName(InetAddress netAddress) {
if (null == netAddress) {
return null;
}
String name = netAddress.getHostName(); // get the host address
return name;
}
String hostIp = "";
InetAddress netAddress = getInetAddress();
hostIp = getHostIp(netAddress);
return hostIp;
}
public static InetAddress getInetAddress() {
try {
return InetAddress.getLocalHost();
} catch (UnknownHostException e) {
System.out.println("unknown host!");
}
return null;
}
public static String getHostIp(InetAddress netAddress) {
if (null == netAddress) {
return null;
}
String ip = netAddress.getHostAddress(); // get the ip address
return ip;
}
public static String getHostName(InetAddress netAddress) {
if (null == netAddress) {
return null;
}
String name = netAddress.getHostName(); // get the host address
return name;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |