作者: falcon 發(fā)表日期: 2006-09-27 15:27
復制鏈接
前些天由于項目需要,自己整了一個比較全面的獲取IP地址的函數(shù):
可以獲取本地的IP地址,也可以根據(jù)域名獲取IP地址,感覺比較有用特此奉獻上,呵呵。
下面是源代碼
Code:
[Ctrl+A Select All]
下面是一個測試的代碼
test_GetIp.c
Code:
[Ctrl+A Select All]
具體使用演示
引文:
$./test_GetIp xxxy.lzu.edu.cn --這里是根據(jù)域名轉(zhuǎn)換為IP地址
domain name or ip address : xxxy.lzu.edu.cn
current ip address: 202.201.0.237
$ ./test_GetIp 219.246.79.7 --輸入地址返回地址
domain name or ip address : 219.246.79.7
current ip address: 219.246.79.7
$ ./test_GetIp localhost --獲取本地IP地址
domain name or ip address : localhost
current ip address: 219.246.79.4