我想在中从域名中获得IP地址(而不是请求)
https://google.com ==> 142.251.40.142发布于 2022-09-08 04:40:36
至少您需要从请求中提取域名或基url。然后,使用该域名通过Java的InetAddress类获取IP地址。
代码:
@RequestMapping("/extract")
public void extract(HttpServletRequest request) throws MalformedURLException {
String domainName = ServletUriComponentsBuilder.fromRequestUri(request)
.replacePath(null)
.build()
.toUriString();
InetAddress ip = InetAddress.getByName(new URL(domainName).getHost());
System.out.println(ip);
}https://stackoverflow.com/questions/73638474
复制相似问题