![](/img/trans.png)
[英]How can i get the username and domain name of client system in java as i can get the ip address and host name using request.getRemoteHost
[英]How can i check System IP Address/Host Name in Java?
有沒有辦法找到系統IP地址而不使用外部進程? 我想為我的應用程序獲取此信息,但如果可能的話,在純Java中。
這符合您的需求嗎?
import java.net.*;
import java.io.*;
import java.applet.*;
public class GetClientIP extends Applet {
public void init() {
try {
InetAddress thisIp =
InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
}
}
InetAddress.getLocalHost()。getHostAddress()調用並不總是有效; 有時它返回127.0.0.1。
請參閱java InetAddress.getLocalHost(); 返回127.0.0.1 ...如何獲得REAL IP? 了解更多細節和其他選擇。
如果你想在java應用程序中找到ip地址
InetAddress localIP=InetAddress.getLocalHost();
如果您使用的是Web應用程序
request.getRemoteAddr();
嗨,是的,可以使用InetAddres類。 檢查此鏈接JAVA API ,您需要的方法是getHostAddress()
考慮使用NetworkInterface類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.