PB9中通过网址(域名)获取IP的方法(转载)
来源:互联网 发布:人工智能对于社会坏处 编辑:程序博客网 时间:2024/04/29 03:06
https://www.2cto.com/database/201202/119983.html
将以下内容保存为本地文件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]
string ls_HostName = space(128)
gethostname ( ls_HostName, len(ls_HostName) ) -小安子添加,电脑名称20171016
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的专栏
- PB9中通过网址(域名)获取IP的方法
- PB9中通过网址(域名)获取IP的方法(转载)
- 如何获取域名(网址)对应的IP地址
- 如何获取域名(网址)对应的IP地址
- [Java] 通过域名获取IP地址的方法与作用
- 通过网址域名查IP
- 域名中ip和端口的问题,java通过域名获取ip
- VC中通过域名获取IP
- SQL语句通过网址获取主域名方法
- 如何在.net中获取电脑名称,IP地址,用户名,计算机所在域名(转载)
- 通过域名获取IP地址
- 通过域名获取ip地址
- 通过域名获取ip地址
- 通过域名获取IP地址
- Qt通过域名获取ip
- php获取ip及网址的方法
- 从网址中获取域名,目录名,文件名的C#方法
- 解决域名转IP的问题(转载)
- 玩转Linux系统-elasticsearch搭建
- htseq-count的使用
- 系统运行级别
- 20171017日记账流水
- C#配置多数据源访问
- PB9中通过网址(域名)获取IP的方法(转载)
- C++/C中防止头文件的重复包含的解决办法及区别
- ORACLE SEQUENCE 的用法
- css3画图之大白(●—●)
- 关于python的基础知识16 -- module.method()
- Spring Boot (四):日志管理
- 数据结构——栈
- Spring Cloud和Docker构建微服务
- vnc的两种配置方法及解决vnc连不上的情况