方法一:
foreach (ipaddress ip in dns.gethostentry(dns.gethostname()).addresslist)
}
方法二:
iphostentry ipentry = dns.gethostbyname(dns.gethostname());//gethostbyname()方法已過時
string ip = ipentry.addresslist[0].tostring();
messagebox.show(ip);
方法三:
string ip = system.net.dns.resolve(system.net.dns.gethostname()).addresslist.getvalue(0).tostring();方法已過時
messagebox.show(ip);
方法四:
ipglobalproperties ipinfo = ipglobalproperties.getipglobalproperties();
//返回有關本地計算機上的 internet 協議版本 4 (ipv4) 傳輸控制協議 (tcp) 連線的資訊。
tcpconnectioninformation ipstaticip4 = ipinfo.getactivetcpconnections();
ipendpoint localendpoint = ipstaticip4[ipstaticip4.length - 1].localendpoint;
string ip = localendpoint.address.tostring();
messagebox.show(ip);
歡迎補充……
獲取本地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...
vc獲取本地IP
include include pragma comment lib,ws2 32.lib void getlocalip void for int i 0 phe h addr list i 0 i wsacleanup int main void wsadata wsddata 這個結構被用來儲...