Issue
I want to get IP address from domain name in Spring Boot App (not from request)
https://google.com ==> 142.251.40.142
Solution
At least you need to extract domain name or base url from the request. Then, use that domain name to get the IP Address via Java's InetAddress
class.
Code :
@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);
}
Answered By - Anish B.
Answer Checked By - Terry (JavaFixing Volunteer)