I am trying to write a program in Java to know whether a machine is in Global/Private network or not. Below is my code snippet. I thought if a machine detects only loopback address(127.0.0.1
or ::1
) then it can be assumed that machine is not in network. But in one of the System where multicast is enabled, I am getting following IP Addresses other than loop back address.
fe80::20c:29ff:fe90:8041 ff01::1, ff02::1 ff02::1:ff90:8041 fe80::ffff:ffff:fffd ::1 fe80::1 127.0.0.1 224.0.0.1
Code snippet:
private static ArrayList< InetAddress > getInetAddresses( ) throws IPAddressException
{
ArrayList< InetAddress > arrayIPAddress = new ArrayList< InetAddress >( );
try
{
Enumeration< NetworkInterface > networkInterfaces = NetworkInterface.getNetworkInterfaces( );
if ( networkInterfaces == null )
{
throw new IPAddressException( "NetworkInterface Not found" );
}
while ( networkInterfaces.hasMoreElements( ) )
{
NetworkInterface card = ( NetworkInterface ) networkInterfaces.nextElement( );
Enumeration< InetAddress > addresses = card.getInetAddresses( );
if ( addresses == null )
{
continue;
}
while ( addresses.hasMoreElements( ) )
{
InetAddress inetAddress = ( InetAddress ) addresses.nextElement( );
arrayIPAddress.add( inetAddress );
}
}
}
catch ( SocketException obj )
{
throw new IPAddressException( "NetworkInterface Not found" );
}
return arrayIPAddress;
}
IPConfig report:
C:\Documents and Settings\Administrator>ipconfig /all Windows IP Configuration Host Name . . . . . . . . . . . . : vm13autopassdl1 Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Unknown IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No DNS Suffix Search List. . . . . . : ind.hp.com india.hp.com Ethernet adapter Local Area Connection 2: Media State . . . . . . . . . . . : Media disconnected Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection # 2 Physical Address. . . . . . . . . : 00-0C-29-90-80-41 Tunnel adapter Teredo Tunneling Pseudo-Interface: Connection-specific DNS Suffix . : Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface Physical Address. . . . . . . . . : FF-FF-FF-FF-FF-FF-FF-FF DHCP Enabled. . . . . . . . . . . : No IP Address. . . . . . . . . . . . : fe80::ffff:ffff:fffd%4 Default Gateway . . . . . . . . . : NetBIOS over Tcpip. . . . . . . . : Disabled
Is there any other way to detect whethre machine is not in network?