-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIPAddressFinder.java
More file actions
28 lines (28 loc) · 971 Bytes
/
IPAddressFinder.java
File metadata and controls
28 lines (28 loc) · 971 Bytes
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
import java.net.*;
import java.util.*;
public class IPAddressFinder
{
public static ArrayList<String> get(){
ArrayList<String> list=new ArrayList<String>();
try{
Enumeration<NetworkInterface> eth=NetworkInterface.getNetworkInterfaces();
while(eth.hasMoreElements()){
NetworkInterface e=eth.nextElement();
//System.out.println(e);
if(!(e.isLoopback()||e.isVirtual())&&e.isUp()){
Enumeration<InetAddress> address=e.getInetAddresses();
while(address.hasMoreElements()){
InetAddress add=address.nextElement();
if(add instanceof Inet4Address){
list.add(add.getHostAddress());
}
}
}
}
}
catch(Exception e){
System.err.println(e);
}
return list;
}
}