zoukankan      html  css  js  c++  java
  • PB9 获取ip与计算机名

    //建立全局的结构s_wsadata 
    //结构如下: 
    //version                                   unsignedinteger 
    //highversion                           unsignedinteger 
    //description[257]                 character 
    //systemstatus[129]               character 
    //maxsockets                             unsignedinteger 
    //maxupddg                                 unsignedinteger 
    //vendorinfo                             string 

    //   声明   extern   function

    type prototypes
    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"
    end prototypes

    函数gf_getip (integer name_ip) 

    函数代码如下:

    s_wsadata l_WSAData
    string ls_HostName = space(128)
    string ls_IpAddress
    int li_version = 257
    blob{4} lb_hostaddress
    /* Then, create a session, based on the winsock version. This version number consists of two part, a major and minor release number, both represented in a byte. So, version 1.1 gives us an integer version of 257 ( 256 + 1 ) */
    IF wsastartup ( li_version, l_WSAData ) = 0 THEN
    /* the wsadata structure contains several information. The description element tells us the winsock version */
    //messagebox("Winsock Version", l_WSAData.description )
    /* Now, let's find out what the hostname is of the current machine we're working on */
    IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN
    messagebox("GetHostName",WSAGetLastError())
    ELSE
    /* With the hostname, call the DLL function and map the IP-address pointers to a PB blob variable, with a length of 4 bytes. This is done because the internal structure contains 4 pointers, each pointer point to one of the parts of the IP-address. An IP-address namely, consists of 4 bytes */
    // Messagebox("Hostname", ls_HostName)
    GetHost(ls_HostName, lb_HostAddress)
    /* Convert the pointers to scalars, and concatenate them to one string, the IP-address */
    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
    /* We're finished, clean up the mess we made */
    WSACleanup()
    ELSE
    messagebox("GetHostName",WSAGetLastError())
    END IF

    if name_ip=1 then
    return ls_hostname
    else
    return ls_ipaddress
    end if

  • 相关阅读:
    INFORMATION_SCHEMA.COLUMNS表的字段信息
    如何取得一个数据表的所有列名
    CASE 函数
    Js定制窗口
    获取当前数据库中的所有用户表
    Js让状态栏不显示链接地址
    RA病人关节残障与软骨破坏而非骨破坏相关
    抗阿达木单抗的抗体可能与阿达木单抗治疗过程中静脉和动脉血栓事件相关
    长期应用阿达木单抗时所产生的抗抗体会影响疗效
    多普勒超声预测抗TNFα治疗类风湿关节炎患者的有效性:一项前瞻性队列研究
  • 原文地址:https://www.cnblogs.com/myjoan/p/6495729.html
Copyright © 2011-2022 走看看