//函式名稱: f_getip
//呼叫方法: f_getip(ip_name)
//返回結果: string :由ip_name決定的反回結果
//建立全域性的結構s_wsadata
//結構如下:
//version unsignedinteger
//highversion unsignedinteger
//description[257] character
//systemstatus[129] character
//maxsockets unsignedinteger
//maxupddg unsignedinteger
//vendorinfo string
// 宣告gloabe extern function
//function int wsastartup( uint uiversionrequested, ref s_wsadata lpwsadata ) library "wsock32.dll "
//function int wsacleanup() library "wsock32.dll "
//function int wsagetlasterror ( ) library "wsock32.dll "
//function int gethostname ( ref string name, int namelen ) library "wsock32.dll "
//function string gethost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll "
//function long getmacaddress(long lana,ref long addr[6]) library "getmac.dll"
//function long getlanaid(ref long lana[254]) library "getmac.dll"
s_wsadata l_wsadata
string ls_hostname = space(128)
string ls_ipaddress
int li_version = 257
blob lb_hostaddress
//建立乙個訊息,基本的 winsock 版本 版本號分為兩部分,主版本號從版本號
if wsastartup ( li_version, l_wsadata ) = 0 then
// 通過結構傳遞版本資訊,類元素告訴我們版本資訊。
//messagebox( "winsock version ", l_wsadata.description )
//獲得當前主機的主機名稱
if gethostname ( ls_hostname, len(ls_hostname) ) < 0 then
messagebox( "gethostname ",wsagetlasterror())
else
//通過主機名,呼叫dll函式取得ip_address的指標給pb blob 變數,長度是4個位元組。因為內部結構包括4個指
//針,每乙個指標指向ip_address的一部分,總共是4個位元組
// messagebox( "hostname ", ls_hostname)
gethost(ls_hostname, lb_hostaddress)
//改變指標的獲得ip_address構造ip位址 27pbws32.dll
ls_ipaddress = string(asc(string(blobmid(lb_hostaddress,1,1))), "000 ") + ". "
ls_ipaddress += string(asc(string(blobmid(lb_hostaddress,2,1))), "000 ") + ". "
ls_ipaddress += string(asc(string(blobmid(lb_hostaddress,3,1))), "000 ") + ". "
ls_ipaddress += string(asc(string(blobmid(lb_hostaddress,4,1))), "000 ")
//messagebox( "ip address ", ls_ipaddress )
end if
//清除所建創的資訊
wsacleanup()
else
messagebox( "gethostname ",wsagetlasterror())
end if
long ll_mac[6]
long ll_lana[254],ll_lananum
integer ll_nub
string ls_mac
long ll_numb
ll_lananum = getlanaid(ll_lana)
for ll_nub=1 to ll_lananum
if getmacaddress(ll_lana[ll_nub],ll_mac) = 0 then
ls_mac=string(string(f_change_jz(ll_mac[1],16))+ '- '+&
messagebox( "lana " + string(ll_lana[ll_nub]),&
string(ll_mac[1])+ ", " + &
string(ll_mac[2])+ ", " + &
string(ll_mac[3])+ ", " + &
string(ll_mac[4])+ ", " + &
string(ll_mac[5])+ ", " + &
string(ll_mac[6]))
end if
next
choose case ip_name
case 1
return "本機名 "+ ls_hostname+ " ip "+ls_ipaddress+ " mac "+ls_mac
case 2
return "本機名: "+ls_hostname
case 3
case 4
end choose
得到本機IP位址
方法1 通過網域名稱得到 目標板沒有網域名稱,無法取得 void print ip lst while hp h addr list id null 方法2 ioctl 已驗證 include include int get ip address r1 char ip,char netmask io...
得到本機機器名 IP位址及其類別
var ip string ipstr string buffer array 1.32 of char i integer wsdata twsadata host phostent begin if wsastartup 2,wsdata 0 then 為程式使用ws2 32.dll初始化 be...
用c語言得到linux本機的IP位址
include include include include include include include include include define eth name eth0 int main strncpy ifr.ifr name,eth name,ifnamsiz ifr.ifr n...