当前位置: 代码迷 >> PB >> 怎么根据域名获得IP地址
  详细解决方案

怎么根据域名获得IP地址

热度:100   发布时间:2016-04-29 09:54:25.0
如何根据域名获得IP地址
如何根据域名获得IP地址?

------解决方案--------------------
将以下内容保存为本地文件n_cst_ip.sru,然后导入pbl中
C/C++ code
$PBExportHeader$n_cst_ip.sruforwardglobal type n_cst_ip from nonvisualobjectend typetype s_wsadata from structure within n_cst_ipend typetype os_hostent from structure within n_cst_ipend typeend forwardtype s_wsadata from structure    unsignedinteger        version    unsignedinteger         highversion     character        discription[257]    character        systemstatus[129]    unsignedinteger        maxsockets    unsignedinteger        maxupddg    string         vendorinfoend typetype os_hostent from structure    long        hname    long        haliases    integer        haddrtype    integer        hlen    long        haddrlistend typeglobal type n_cst_ip from nonvisualobject autoinstantiateend typetype prototypesFUNCTION  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 prototypesforward prototypespublic function boolean of_getdnsip (string as_dns, ref string as_ipadress[])end prototypespublic 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   //修改人:yyoingestring ls_IpAddress[]int li_IP_Counts_wsadata l_WSADataULong ll_addr, ll_IP, ll_ipaddr, ll_stringip  int li_version = 257blob{128} lb_HostNameulong ll_addr_listos_hostent lstr_hostentif 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 ifas_ipadress = ls_IpAddressreturn upperbound(as_ipadress) > 0 //取到IP则返回trueend functionon n_cst_ip.createcall super::createTriggerEvent( this, "constructor" )end onon n_cst_ip.destroyTriggerEvent( this, "destructor" )call super::destroyend on
  相关解决方案