public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Get client's IP address
String ipAddress = req.getRemoteAddr(); // ip
// Get client's hostname
String hostname = req.getRemoteHost(); // hostname
}
import java.net.*;
public class IP {
public static void main(String[] args) throws Exception {
System.out.println(InetAddress.getLocalHost());
System.out.println(InetAddress.getByName("www.xxx.com"));
}
}
3条答案
按热度按时间oxcyiej71#
我想你想用
InetSocketAddress.getAddress()
喜欢或者,你可以使用
String.split(String)
喜欢jjjwad0x2#
servletrequest.getremoteaddr()
string ipaddress=request.getremoteaddr();
unftdfkk3#
req.getRemoteAddr()
方法是什么如果你有servlet