-
Notifications
You must be signed in to change notification settings - Fork 0
/
getIP.java
34 lines (30 loc) · 1.03 KB
/
getIP.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.net.*;
import java.io.*;
import java.util.*;
import java.net.InetAddress;
public class JavaProgram
{
public static void main(String args[]) throws Exception
{
// Returns the instance of InetAddress containing
// local host name and address
InetAddress localhost = InetAddress.getLocalHost();
System.out.println("System IP Address : " +
(localhost.getHostAddress()).trim());
// Find public IP address
String systemipaddress = "";
try
{
URL url_name = new URL("http://bot.whatismyipaddress.com");
BufferedReader sc =
new BufferedReader(new InputStreamReader(url_name.openStream()));
// reads system IPAddress
systemipaddress = sc.readLine().trim();
}
catch (Exception e)
{
systemipaddress = "Cannot Execute Properly";
}
System.out.println("Public IP Address: " + systemipaddress +"\n");
}
}