- import java.net.InetAddress;
- import java.net.InterfaceAddress;
- import java.net.NetworkInterface;
- import java.util.List;
- public class F {
- public static void main(String[] args) throws Exception
- {
- InetAddress ia=InetAddress.getLocalHost();
- NetworkInterface ni=NetworkInterface.getByInetAddress(ia);
- List<InterfaceAddress> list=ni.getInterfaceAddresses();;
- for(int i=0;i<list.size();i++)
- {
- InterfaceAddress ifa=list.get(i);
- InetAddress f=ifa.getAddress();
- System.out.println(f.getHostAddress());
- }
- }
- }
复制代码 |