my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes How to know programmatically whether a machne is in Global/Private network ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to know programmatically whether a machne is in Global/Private network ?" Watch "How to know programmatically whether a machne is in Global/Private network ?" New topic
Author

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

T Sahu
Greenhorn

Joined: Sep 06, 2010
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to know programmatically whether a machne is in Global/Private network ?
 
Similar Threads
Apache not working when connected to Wireless LAN
Problems with Java RMI when having multiple IPs (private IP and public IP)
NetworkInterface.isUp() is returning false for the interface which is up
RMI problem with Localhost
Problem in RDBMS