This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to know programmatically whether a machne is in Global/Private network ?

 
T Sahu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ,

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


So Is there any other way to detect whether machine is not in network?

Regards,
Tripati
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic