將以下內容保存為本地文件n_cst_ip.sru,然後導入pbl中
[cpp]
$PBExportHeader$n_cst_ip.sru
forward
global type n_cst_ip from nonvisualobject
end type
type s_wsadata from structure within n_cst_ip
end type
type os_hostent from structure within n_cst_ip
end type
end forward
type s_wsadata from structure
unsignedinteger version
unsignedinteger highversion
character discription[257]
character systemstatus[129]
unsignedinteger maxsockets
unsignedinteger maxupddg
string vendorinfo
end type
type os_hostent from structure
long hname
long haliases
integer haddrtype
integer hlen
long haddrlist
end type
global type n_cst_ip from nonvisualobject autoinstantiate
end type
type prototypes
FUNCTION int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll"
FUNCTION int WSACleanup() library "wsock32.dll"
FUNCTION int gethostname ( ref blob name, int namelen ) library "wsock32.dll"
FUNCTION uLong gethostbyname(ref blob sHost) Library "wsock32.dll"
FUNCTION uLong RtlMoveMemory(ref os_hostent hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll"
FUNCTION uLong RtlMoveMemory(ref uLong hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll"
end prototypes
forward prototypes
public function boolean of_getdnsip (string as_dns, ref string as_ipadress[])
end prototypes
public function boolean of_getdnsip (string as_dns, ref string as_ipadress[]);//函 數:of_GetDNSIp()
//功 能:得到指定域名的IP
//參 數:string as_DNS //域名
// ref string as_ipadress[] //返回的ip數組
//返回值:Boolean True/False
//修改人:yyoinge
string ls_IpAddress[]
int li_IP_Count
s_wsadata l_WSAData
ULong ll_addr, ll_IP, ll_ipaddr, ll_stringip
int li_version = 257
blob{128} lb_HostName
ulong ll_addr_list
os_hostent lstr_hostent
if wsastartup(li_version, l_WSAData) = 0 then
lb_hostname = blob('www.baidu.com')
ll_addr = gethostbyname(lb_HostName)
RtlMoveMemory(lstr_hostent, ll_addr, 16)
ll_addr_list = lstr_hostent.haddrlist
li_IP_Count = 0
Do While True
RtlMoveMemory(ll_IPAddr, ll_addr_list, 4 )
If ll_IPAddr = 0 Then Exit
li_IP_Count = li_IP_Count + 1
RtlMoveMemory(ll_StringIP, ll_IPAddr, 1)
ls_IpAddress[li_IP_Count] = string(ll_StringIP) + "."
RtlMoveMemory(ll_StringIP, ll_IPAddr + 1, 1)
ls_IpAddress[li_IP_Count] = ls_IpAddress[li_IP_Count] + string(ll_StringIP) + "."
RtlMoveMemory(ll_StringIP, ll_IPAddr + 2, 1)
ls_IpAddress[li_IP_Count] = ls_IpAddress[li_IP_Count] + string(ll_StringIP)+ "."
RtlMoveMemory(ll_StringIP, ll_IPAddr + 3, 1)
ls_IpAddress[li_IP_Count] = ls_IpAddress[li_IP_Count] + string(ll_StringIP)
ll_addr_list = ll_addr_list + 4
Loop
WSACleanup()
End if
as_ipadress = ls_IpAddress
return upperbound(as_ipadress) > 0 //取到IP則返回true
end function
on n_cst_ip.create
call super::create
TriggerEvent( this, "constructor" )
end on
on n_cst_ip.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
程序中這樣調用即可:
[cpp]
n_cst_ip ln
string ls_dsn = 'www.baidu.com',ls[]
if ln.of_getdnsip(ls_dsn, ls) then
long i
for i = 1 to upperbound(ls)
messagebox('提示', '域名【' + ls_dsn + '】對應的IP地址(' + string(i) + ')為:~r~n~r~n' + ls[i])
next
end if
摘自 yyoinge的專欄