2012-01-11 13 views
0

私は有線LANまたは無線LAN内でファイルbtwを転送するJavaサーバークライアントアプリケーションを開発中です。クライアントコンピュータのIPアドレスを検出する方法が問題です無線または有線LAN内のサーバコンピュータとを含む。ボトムライン:Javaコードを使用して有線または無線LAN接続のコンピュータのIPアドレスを検出する方法2台のコンピュータ。Javaを使用した有線/無線LANのIPアドレス

+1

あなたは、関連する質問を見たことがありますか? http://stackoverflow.com/questions/2845279/、http://stackoverflow.com/questions/8083479/ –

答えて

0
import java.io.*; 
import java.net.*; 
import java.util.*; 
import static java.lang.System.out; 

public class ListNets { 

public static void main(String args[]) throws SocketException, UnknownHostException { 
    System.out.println(System.getProperty("os.name")); 
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); 
    for (NetworkInterface netint : Collections.list(nets)) 
     if (netint.getName().equals("wlan0") || netint.getName().equals("en0")) { 
      displayInterfaceInformation(netint); 
     }  
} 

static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { 
    out.printf("Display name: %s\n", netint.getDisplayName()); 
    out.printf("Name: %s\n", netint.getName()); 
    Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); 
    for (InetAddress inetAddress : Collections.list(inetAddresses)) { 

     out.printf("InetAddress: %s\n", inetAddress); 
    } 
    out.printf("\n"); 
} 
} 
関連する問題