设为首页 加入收藏

TOP

PB9中通过网址(域名)获取IP的方法(一)
2014-11-23 22:54:19 来源: 作者: 【 】 浏览:17
Tags:PB9 通过 网址 域名 获取 方法
将以下内容保存为本地文件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
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SybSQLException: The datastream.. 下一篇pb控件强化:一个在drag时可以自..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: