Get secondary IP of an NIC in Java -


the eth1 interface of vm follows:

3: eth1: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state qlen 1000 link/ether 08:00:27:d3:c9:30 brd ff:ff:ff:ff:ff:ff inet 10.0.10.13/24 brd 10.0.10.255 scope global eth1 inet 10.0.10.101/24 scope global secondary eth1 inet6 fe80::a00:27ff:fed3:c930/64 scope link    valid_lft forever preferred_lft forever 

i want secondary ip (i.e. 10.0.10.101) of interface in java.

using getinetaddresses() method of class networkinterface, can ips of interface, how can know 1 secondary ip?

any appreciated.

=============================================================

update: following simplified version of code. basically, want figure out how commented line (i.e. if condition) should written.

string geteth1secondaryip() throws socketexception {     networkinterface eth1 = networkinterface.getbyname("eth1");     enumeration<inetaddress> inetaddrs = eth1.getinetaddresses();     while(inetaddrs.hasmoreelements()) {         inetaddress addr = inetaddrs.nextelement();         //if(addr secondary ip) {             return addr.gethostaddress();         //}     }     return null; } 


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -