클라이언트의 IP 주소를 찾으려면 Java 코드는 다음과 같습니다. -
예시
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;
public class Demo{
public static void main(String args[]) throws Exception{
InetAddress my_localhost = InetAddress.getLocalHost();
System.out.println("The IP Address of client is : " + (my_localhost.getHostAddress()).trim());
String my_system_address = "";
try{
URL my_url = new URL("https://bot.whatismyipaddress.com");
BufferedReader my_br = new BufferedReader(new
InputStreamReader(my_url.openStream()));
my_system_address = my_br.readLine().trim();
}
catch (Exception e){
my_system_address = "Cannot Execute Properly";
}
}
} 출력
The IP Address of client is : 127.0.0.1
Demo라는 클래스에는 주요 기능이 포함되어 있습니다. 이 메인 함수에서 InetAddress 클래스의 인스턴스가 생성되고 'getHostAddress' 함수를 사용하여 클라이언트의 IP 주소를 가져옵니다. 콘솔에 표시됩니다.