[英]Get the local IP address associated to a local MAC address
在.properties
文件中,我存儲了我的Java應用程序要使用的本地網絡接口(即MAC地址)。 然后,我將該信息作為屬性。
現在,我想獲取當前與此MAC地址關聯的本地IP地址。 我怎么用Java做到這一點?
請注意,我無法在網關上使用反向ARP。 我沒有任何網關,僅在本地工作。
謝謝。
您可以為此使用NetworkInterface( http://docs.oracle.com/javase/6/docs/api/java/net/NetworkInterface.html ):
Enumeration<NetworkInterface> interfaces =
NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface i = interfaces.nextElement();
if ( i.getHardwareAddress().... ) {
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.