由於專案上的原因,需要獲取本地ip與網路ip及mac位址,弄了好半天,才明白過程,於是給大家分享一下。
不說了,直接上**。
public class getipandmacaddress
/*** 獲取鏈結網路時分配的ip
* @throws socketexception
*/public static string getintentip() throws socketexception}}
system.out.println("mac--:"+getipandmacaddress.getmacaddress(getintentip()));
} }
獲取本地IP
bool socketuti getlocalipaddr string stripaddr if gethostname myname,80 socket error return false if thishost gethostbyname myname return false memset...
獲取本地IP
本機可能會有多個ip,下面這段程式可以獲得本機ip struct hostent h char host 100 int i gethostname host,100 if h gethostbyname host null printf error s n hstrerror h errno re...
獲取本地IP
方法一 foreach ipaddress ip in dns.gethostentry dns.gethostname addresslist 方法二 iphostentry ipentry dns.gethostbyname dns.gethostname gethostbyname 方法已過時...