1 #include 2 #include 3 #include "vs成功例項:iphlpapi.h"//
包含對ip幫助函式的定義
4#pragma comment(lib,"iphlpapi.lib")
5#pragma comment(lib,"ws2_32.lib")//
全域性資料
6 u_char g_uclocalmac[6];7
dword g_dwgatewayip;
8dword g_dwlocalip;
9dword g_dwmask;
10bool getglobaldata()
1127}28
29 printf("
\n ---------------------本地主機資訊---------------------\n\n");
30 in_addr in;31
in.s_un.s_addr =g_dwlocalip;
32 printf("
ip address : %s\n
",::inet_ntoa(in
));33
34in.s_un.s_addr =g_dwmask;
35 printf("
subnet mask : %s\n
",::inet_ntoa(in
));36
37in.s_un.s_addr =g_dwgatewayip;
38 printf("
default gateway:%s\n
",::inet_ntoa(in
));39
40 u_char *p =g_uclocalmac;
41 printf("
mac address:%02x-%02x-%02x-%02x-%02x-%02x\n
",p[0],p[1],p[2],p[3],p[4],p[5
]);42
43 printf("
\n\n");
4445
return
true;
46 }
1結果如下:: 定義控制台應用程式的入口點。2//
34 #include "
stdafx.h
"5 #include 6 #include 7 #include "
iphlpapi.h"//
包含對ip幫助函式的定義
8#pragma comment(lib,"iphlpapi.lib")
9#pragma comment(lib,"ws2_32.lib")//
全域性資料
10 u_char g_uclocalmac[6
];11
dword g_dwgatewayip;
12dword g_dwlocalip;
13dword g_dwmask;
14bool getglobaldata()
1531}32
33 printf("
\n ---------------------本地主機資訊---------------------\n\n");
34 in_addr in;35
in.s_un.s_addr =g_dwlocalip;
36 printf("
ip address : %s\n
",::inet_ntoa(in
));37
38in.s_un.s_addr =g_dwmask;
39 printf("
subnet mask : %s\n
",::inet_ntoa(in
));40
41in.s_un.s_addr =g_dwgatewayip;
42 printf("
default gateway:%s\n
",::inet_ntoa(in
));43
44 u_char *p =g_uclocalmac;
45 printf("
mac address:%02x-%02x-%02x-%02x-%02x-%02x\n
",p[0],p[1],p[2],p[3],p[4],p[5
]);46
47 printf("
\n\n");
4849
return
true;50}
5152
int _tmain(int argc, _tchar*ar**)
53
xingoo 閱讀(
...)
編輯收藏
python獲取本機IP mac位址 計算機名
在python中獲取ip位址和在php中有很大不同,在php中往往比較簡單。那再python中怎麼做呢?12 34import def mac uuid.uuid inthex 12 return.join mac e e 2forin 0,11,2 下面再來看一下python獲取ip的方法 使用s...
C socket實現獲取本機IP MAC
include 該標頭檔案定義了socket程式設計的功能 include 該標頭檔案宣告了輸入輸出流函式 include 該標頭檔案定義了一些通用函式 include 該標頭檔案支援http請求 include 該標頭檔案定義了windows的所有資料基本型態 include 該標頭檔案宣告了ne...
獲取本機IP位址
cstring strlocalip char szhostname 64 memset szhostname,0x00,sizeof szhostname gethostname szhostname,sizeof szhostname phostent phost gethostbyname s...