您的位置:程序门 -> vb -> 网络编程



实现ping功能


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


实现ping功能[已结贴,结贴人:guo2478858]
发表于:2008-01-28 14:36:46 楼主
想用vb写一个实现ping目标网址的小功能,我是菜鸟一个,不知道该怎么写?可以给一个现成的代码琢磨吗?
发表于:2008-01-28 15:47:211楼 得分:0
建一模块:
attribute   vb_name   =   "module1"
option   explicit
private   const   ip_success   as   long   =   0
private   const   ip_status_base   as   long   =   11000
private   const   ip_buf_too_small   as   long   =   (11000   +   1)
private   const   ip_dest_net_unreachable   as   long   =   (11000   +   2)
private   const   ip_dest_host_unreachable   as   long   =   (11000   +   3)
private   const   ip_dest_prot_unreachable   as   long   =   (11000   +   4)
private   const   ip_dest_port_unreachable   as   long   =   (11000   +   5)
private   const   ip_no_resources   as   long   =   (11000   +   6)
private   const   ip_bad_option   as   long   =   (11000   +   7)
private   const   ip_hw_error   as   long   =   (11000   +   8)
private   const   ip_packet_too_big   as   long   =   (11000   +   9)
private   const   ip_req_timed_out   as   long   =   (11000   +   10)
private   const   ip_bad_req   as   long   =   (11000   +   11)
private   const   ip_bad_route   as   long   =   (11000   +   12)
private   const   ip_ttl_expired_transit   as   long   =   (11000   +   13)
private   const   ip_ttl_expired_reassem   as   long   =   (11000   +   14)
private   const   ip_param_problem   as   long   =   (11000   +   15)
private   const   ip_source_quench   as   long   =   (11000   +   16)
private   const   ip_option_too_big   as   long   =   (11000   +   17)
private   const   ip_bad_destination   as   long   =   (11000   +   18)
private   const   ip_addr_deleted   as   long   =   (11000   +   19)
private   const   ip_spec_mtu_change   as   long   =   (11000   +   20)
private   const   ip_mtu_change   as   long   =   (11000   +   21)
private   const   ip_unload   as   long   =   (11000   +   22)
private   const   ip_addr_added   as   long   =   (11000   +   23)
private   const   ip_general_failure   as   long   =   (11000   +   50)
private   const   max_ip_status   as   long   =   (11000   +   50)
private   const   ip_pending   as   long   =   (11000   +   255)
private   const   ping_timeout   as   long   =   500
private   const   ws_version_reqd   as   long   =   &h101
private   const   min_sockets_reqd   as   long   =   1
private   const   socket_error   as   long   =   -1
private   const   inaddr_none   as   long   =   &hffffffff
private   const   max_wsadescription   as   long   =   256
private   const   max_wsasysstatus   as   long   =   128

private   type   icmp_options
        ttl   as   byte
        tos   as   byte
        flags   as   byte
        optionssize   as   byte
        optionsdata   as   long
end   type

public   type   icmp_echo_reply
        address   as   long
        status   as   long
        roundtriptime   as   long
        datasize   as   long
        'formerly   integer
        'reserved   as   integer
        datapointer   as   long
        options   as   icmp_options
        data   as   string   *   250
end   type

private   type   wsadata
        wversion   as   integer
        whighversion   as   integer
        szdescription(0   to   max_wsadescription)   as   byte
        szsystemstatus(0   to   max_wsasysstatus)   as   byte
        wmaxsockets   as   long
        wmaxudpdg   as   long
        dwvendorinfo   as   long
end   type

private   declare   function   icmpcreatefile   lib   "icmp.dll"   ()   as   long

private   declare   function   icmpclosehandle   lib   "icmp.dll"   (byval   icmphandle   as   long)   as   long

private   declare   function   icmpsendecho   lib   "icmp.dll"   (byval   icmphandle   as   long,   byval   destinationaddress   as   long,   byval   requestdata   as   string,   byval   requestsize   as   long,   byval   requestoptions   as   long,   replybuffer   as   icmp_echo_reply,   byval   replysize   as   long,   byval   timeout   as   long)   as   long

private   declare   function   wsagetlasterror   lib   "wsock32.dll"   ()   as   long

private   declare   function   wsastartup   lib   "wsock32.dll"   (byval   wversionrequired   as   long,   lpwsadata   as   wsadata)   as   long

private   declare   function   wsacleanup   lib   "wsock32.dll"   ()   as   long

private   declare   function   gethostname   lib   "wsock32.dll"   (byval   szhost   as   string,   byval   dwhostlen   as   long)   as   long

private   declare   function   gethostbyname   lib   "wsock32.dll"   (byval   szhost   as   string)   as   long

private   declare   sub   copymemory   lib   "kernel32"   alias   "rtlmovememory"   (xdest   as   any,   xsource   as   any,   byval   nbytes   as   long)

private   declare   function   inet_addr   lib   "wsock32.dll"   (byval   s   as   string)   as   long

public   function   getstatuscode(status   as   long)   as   string
        dim   msg   as   string
        select   case   status
                case   ip_success:   msg   =   "ip   success"
                case   inaddr_none:   msg   =   "inet_addr:   bad   ip   format"
                case   ip_buf_too_small:   msg   =   "ip   buf   too_small"
                case   ip_dest_net_unreachable:   msg   =   "ip   dest   net   unreachable"
                case   ip_dest_host_unreachable:   msg   =   "ip   dest   host   unreachable"
                case   ip_dest_prot_unreachable:   msg   =   "ip   dest   prot   unreachable"
                case   ip_dest_port_unreachable:   msg   =   "ip   dest   port   unreachable"
                case   ip_no_resources:   msg   =   "ip   no   resources"
                case   ip_bad_option:   msg   =   "ip   bad   option"
                case   ip_hw_error:   msg   =   "ip   hw_error"
                case   ip_packet_too_big:   msg   =   "ip   packet   too_big"
                case   ip_req_timed_out:   msg   =   "ip   req   timed   out"
                case   ip_bad_req:   msg   =   "ip   bad   req"
                case   ip_bad_route:   msg   =   "ip   bad   route"
                case   ip_ttl_expired_transit:   msg   =   "ip   ttl   expired   transit"
                case   ip_ttl_expired_reassem:   msg   =   "ip   ttl   expired   reassem"
                case   ip_param_problem:   msg   =   "ip   param_problem"
                case   ip_source_quench:   msg   =   "ip   source   quench"
                case   ip_option_too_big:   msg   =   "ip   option   too_big"
                case   ip_bad_destination:   msg   =   "ip   bad   destination"
                case   ip_addr_deleted:   msg   =   "ip   addr   deleted"
                case   ip_spec_mtu_change:   msg   =   "ip   spec   mtu   change"
                case   ip_mtu_change:   msg   =   "ip   mtu_change"
                case   ip_unload:   msg   =   "ip   unload"
                case   ip_addr_added:   msg   =   "ip   addr   added"
                case   ip_general_failure:   msg   =   "ip   general   failure"
                case   ip_pending:   msg   =   "ip   pending"
                case   ping_timeout:   msg   =   "ping   timeout"
                case   else:   msg   =   "unknown   msg   returned"
        end   select
        getstatuscode   =   cstr(status)   &   "["   &   msg   &   "]"
end   function

public   function   ping(saddress   as   string,   sdatatosend   as   string,   echo   as   icmp_echo_reply)   as   long

        'if   ping   succeeds   :
        '.roundtriptime   =   time   in   ms   for   the   ping   to   complete,
        '.data   is   the   data   returned   (null   terminated)
        '.address   is   the   ip   address   that   actually   replied
        '.datasize   is   the   size   of   the   string   in   .data
        '.status   will   be   0
        'if   ping   fails   .status   will   be   the   error   code


        dim   hport   as   long
        dim   dwaddress   as   long

        'convert   the   address   into   a   long   representation
        dwaddress   =   inet_addr(saddress)

        'if   avalid   address,
        if   dwaddress   <>   inaddr_none   then
                'open   a   port
                hport   =   icmpcreatefile()
                'and   if   successful,
                if   hport   then
                        'ping   it.
                        call   icmpsendecho(hport,   dwaddress,   sdatatosend,   len(sdatatosend),   0,   echo,   len(echo),   ping_timeout)
                        'return   the   status   as   ping   succes   and   close
                        ping   =   echo.status
                        call   icmpclosehandle(hport)
                end   if
        else
                'the   address   format   was   probably   invalid
                ping   =   inaddr_none
        end   if

end   function

public   sub   socketscleanup()
        if   wsacleanup()   <>   0   then
                msgbox   "windows   sockets   error   occurred   in   clean   up.",   vbexclamation
        end   if
end   sub

public   function   socketsinitialize()   as   boolean
        dim   wsad   as   wsadata
        socketsinitialize   =   wsastartup(ws_version_reqd,   wsad)   =   ip_success
end   function

public   function   longtoip(ladress   as   long)   as   string
        dim   s,   s1,   s2,   s3,   s4
        s   =   hex(ladress)
        s   =   string(8   -   len(s),   "0")   &   s
        s1   =   "&h"   &   left$(s,   2):   s2   =   "&h"   &   mid$(s,   3,   2):   s3   =   "&h"   &   mid$(s,   5,   2):   s4   =   "&h"   &   right$(s,   2)
        longtoip   =   cdec(s4)   &   "."   &   cdec(s3)   &   "."   &   cdec(s2)   &   "."   &   cdec(s1)
end   function
发表于:2008-01-28 15:52:012楼 得分:0
private   sub   command1_click()

        dim   echo   as   icmp_echo_reply
        dim   pos   as   long
        dim   success   as   long
        dim   s   as   string,   d   as   double,   e   as   long
        if   socketsinitialize()   then

                'ping   the   ip   passing   the   address,text
                'to   send,   and   the   echo   structure.
                success   =   ping(text1.text,   string(cint(text2.text),   "*"),   echo)

                'display   the   results
                text4(0).text   =   getstatuscode(success)
                with   echo
                        text4(1).text   =   longtoip(.address)   &   "("   &   echo.address   &   ")"
                        text4(2).text   =   echo.roundtriptime   &   "ms"
                        text4(3).text   =   echo.datasize   &   "bytes"

                        if   left$(echo.data,   1)   <>   chr$(0)   then
                                pos   =   instr(echo.data,   chr$(0))
                                text4(4).text   =   left$(echo.data,   pos   -   1)
                        end   if
                        text4(5).text   =   echo.datapointer
                        text4(6)   =   .options.ttl
                end   with
                socketscleanup
       
        else
                msgbox   "windows   sockets   for   32bit   windows"   &   "environments   is   not   successfully   responding."
        end   if

end   sub
发表于:2008-01-28 15:53:343楼 得分:0
把窗口给你,这是我用的程序
version   5.00
begin   vb.form   form1  
      caption                   =       "form1"
      clientheight         =       1560
      clientleft             =       60
      clienttop               =       450
      clientwidth           =       6840
      linktopic               =       "form1"
      scaleheight           =       1560
      scalewidth             =       6840
      startupposition   =       3     '窗口缺省
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       6
            left                         =       3000
            tabindex                 =       10
            text                         =       "ttl"
            tooltiptext           =       "ttl"
            top                           =       1200
            width                       =       615
      end
      begin   vb.textbox   text3  
            enabled                   =       0       'false
            height                     =       270
            left                         =       3720
            tabindex                 =       9
            text                         =       "text3"
            top                           =       240
            width                       =       855
      end
      begin   vb.textbox   text2  
            height                     =       270
            left                         =       3000
            tabindex                 =       8
            text                         =       "64"
            top                           =       240
            width                       =       615
      end
      begin   vb.textbox   text1  
            height                     =       270
            left                         =       120
            tabindex                 =       7
            text                         =       "202.165.102.205"
            top                           =       240
            width                       =       2775
      end
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       5
            left                         =       5640
            tabindex                 =       6
            text                         =       "datapointer"
            tooltiptext           =       "datapointer"
            top                           =       1200
            width                       =       1095
      end
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       4
            left                         =       4680
            tabindex                 =       5
            text                         =       "senddata"
            tooltiptext           =       "senddata"
            top                           =       1200
            width                       =       855
      end
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       3
            left                         =       3720
            tabindex                 =       4
            text                         =       "datasize"
            tooltiptext           =       "datasize"
            top                           =       1200
            width                       =       855
      end
      begin   vb.textbox   text4  
            height                     =       375
            index                       =       2
            left                         =       5640
            tabindex                 =       3
            text                         =       "roundtriptime"
            tooltiptext           =       "roundtriptime"
            top                           =       720
            width                       =       975
      end
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       1
            left                         =       120
            tabindex                 =       2
            text                         =       "address"
            tooltiptext           =       "address"
            top                           =       1200
            width                       =       2775
      end
      begin   vb.textbox   text4  
            height                     =       270
            index                       =       0
            left                         =       120
            tabindex                 =       1
            text                         =       "statuscode"
            tooltiptext           =       "statuscode"
            top                           =       840
            width                       =       5415
      end
      begin   vb.commandbutton   command1  
            caption                   =       "start   ping"
            height                     =       375
            left                         =       4680
            tabindex                 =       0
            top                           =       240
            width                       =       2055
      end
end
attribute   vb_name   =   "form1"
attribute   vb_globalnamespace   =   false
attribute   vb_creatable   =   false
attribute   vb_predeclaredid   =   true
attribute   vb_exposed   =   false
option   explicit

private   sub   command1_click()

        dim   echo   as   icmp_echo_reply
        dim   pos   as   long
        dim   success   as   long
        dim   s   as   string,   d   as   double,   e   as   long
        if   socketsinitialize()   then

                'ping   the   ip   passing   the   address,text
                'to   send,   and   the   echo   structure.
                success   =   ping(text1.text,   string(cint(text2.text),   "*"),   echo)

                'display   the   results
                text4(0).text   =   getstatuscode(success)
                with   echo
                        text4(1).text   =   longtoip(.address)   &   "("   &   echo.address   &   ")"
                        text4(2).text   =   echo.roundtriptime   &   "ms"
                        text4(3).text   =   echo.datasize   &   "bytes"

                        if   left$(echo.data,   1)   <>   chr$(0)   then
                                pos   =   instr(echo.data,   chr$(0))
                                text4(4).text   =   left$(echo.data,   pos   -   1)
                        end   if
                        text4(5).text   =   echo.datapointer
                        text4(6)   =   .options.ttl
                end   with
                socketscleanup
       
        else
                msgbox   "windows   sockets   for   32bit   windows"   &   "environments   is   not   successfully   responding."
        end   if

end   sub
发表于:2008-02-03 08:50:184楼 得分:0
有没有直接写好的发给我啊?我会加分。
发表于:2008-02-03 09:06:375楼 得分:10
这就是直接写好的,我正在用的。
只要1楼和3楼的代码就行了。
发表于:2008-02-03 14:51:036楼 得分:0
好的,我去试下,回头结贴散分。
发表于:2008-02-03 14:51:557楼 得分:0
to   z_wenqian:
你的qq或者邮件多少?  
发表于:2008-02-03 14:54:208楼 得分:0
zh_wenqian@yahoo.com.cn
发表于:2008-02-03 17:44:059楼 得分:10
这是我写好的函数,写一个文件直接调用即可

''用法:   ping("192.168.0.1")
''返回值为   > 0则表示通的(ping的响应时间), <0则为不通

option   explicit
 
public   const   ip_status_base   =   11000
public   const   ip_success   =   0
public   const   ip_buf_too_small   =   (11000   +   1)
public   const   ip_dest_net_unreachable   =   (11000   +   2)
public   const   ip_dest_host_unreachable   =   (11000   +   3)
public   const   ip_dest_prot_unreachable   =   (11000   +   4)
public   const   ip_dest_port_unreachable   =   (11000   +   5)
public   const   ip_no_resources   =   (11000   +   6)
public   const   ip_bad_option   =   (11000   +   7)
public   const   ip_hw_error   =   (11000   +   8)
public   const   ip_packet_too_big   =   (11000   +   9)
public   const   ip_req_timed_out   =   (11000   +   10)
public   const   ip_bad_req   =   (11000   +   11)
public   const   ip_bad_route   =   (11000   +   12)
public   const   ip_ttl_expired_transit   =   (11000   +   13)
public   const   ip_ttl_expired_reassem   =   (11000   +   14)
public   const   ip_param_problem   =   (11000   +   15)
public   const   ip_source_quench   =   (11000   +   16)
public   const   ip_option_too_big   =   (11000   +   17)
public   const   ip_bad_destination   =   (11000   +   18)
public   const   ip_addr_deleted   =   (11000   +   19)
public   const   ip_spec_mtu_change   =   (11000   +   20)
public   const   ip_mtu_change   =   (11000   +   21)
public   const   ip_unload   =   (11000   +   22)
public   const   ip_addr_added   =   (11000   +   23)
public   const   ip_general_failure   =   (11000   +   50)
public   const   max_ip_status   =   11000   +   50
public   const   ip_pending   =   (11000   +   255)
public   const   ping_timeout   =   200
public   const   ws_version_reqd   =   &h101
public   const   ws_version_major   =   ws_version_reqd   \   &h100   and   &hff&
public   const   ws_version_minor   =   ws_version_reqd   and   &hff&
public   const   min_sockets_reqd   =   1
public   const   socket_error   =   -1
 
public   const   max_wsadescription   =   256
public   const   max_wsasysstatus   =   128
 
public   type   icmp_options
ttl   as   byte
tos   as   byte
flags   as   byte
optionssize   as   byte
optionsdata   as   long
end   type
 
dim   icmpopt   as   icmp_options
 
public   type   icmp_echo_reply
address   as   long
status   as   long
roundtriptime   as   long
datasize   as   integer
reserved   as   integer
datapointer   as   long
options   as   icmp_options
data   as   string   *   250
end   type
 
public   type   hostent
hname   as   long
haliases   as   long
haddrtype   as   integer
hlen   as   integer
haddrlist   as   long
end   type
 
public   type   wsadata
wversion   as   integer
whighversion   as   integer
szdescription(0   to   max_wsadescription)   as   byte
szsystemstatus(0   to   max_wsasysstatus)   as   byte
wmaxsockets   as   integer
wmaxudpdg   as   integer
dwvendorinfo   as   long
end   type
 
 
public   declare   function   icmpcreatefile   lib   "icmp.dll"   ()   as   long
 
public   declare   function   icmpclosehandle   lib   "icmp.dll"   _
(byval   icmphandle   as   long)   as   long
 
public   declare   function   icmpsendecho   lib   "icmp.dll"   _
(byval   icmphandle   as   long,   _
byval   destinationaddress   as   long,   _
byval   requestdata   as   string,   _
byval   requestsize   as   integer,   _
byval   requestoptions   as   long,   _
replybuffer   as   icmp_echo_reply,   _
byval   replysize   as   long,   _
byval   timeout   as   long)   as   long
 
public   declare   function   wsagetlasterror   lib   "wsock32.dll"   ()   as   long
 
public   declare   function   wsastartup   lib   "wsock32.dll"   _
(byval   wversionrequired   as   long,   _
lpwsadata   as   wsadata)   as   long
 
public   declare   function   wsacleanup   lib   "wsock32.dll"   ()   as   long
 
public   declare   function   gethostname   lib   "wsock32.dll"   _
(byval   szhost   as   string,   _
byval   dwhostlen   as   long)   as   long
 
public   declare   function   gethostbyname   lib   "wsock32.dll"   _
(byval   szhost   as   string)   as   long
 
public   declare   sub   rtlmovememory   lib   "kernel32"   _
(hpvdest   as   any,   _
byval   hpvsource   as   long,   _
byval   cbcopy   as   long)
 
 
public   function   getstatuscode(status   as   long)   as   string
 
dim   msg   as   string
 
select   case   status
case   ip_success:   msg   =   "ip   success"
case   ip_buf_too_small:   msg   =   "ip   buf   too_small"
case   ip_dest_net_unreachable:   msg   =   "ip   dest   net   unreachable"
case   ip_dest_host_unreachable:   msg   =   "ip   dest   host   unreachable"
case   ip_dest_prot_unreachable:   msg   =   "ip   dest   prot   unreachable"
case   ip_dest_port_unreachable:   msg   =   "ip   dest   port   unreachable"
case   ip_no_resources:   msg   =   "ip   no   resources"
case   ip_bad_option:   msg   =   "ip   bad   option"
case   ip_hw_error:   msg   =   "ip   hw_error"
case   ip_packet_too_big:   msg   =   "ip   packet   too_big"
case   ip_req_timed_out:   msg   =   "ip   req   timed   out"
case   ip_bad_req:   msg   =   "ip   bad   req"
case   ip_bad_route:   msg   =   "ip   bad   route"
case   ip_ttl_expired_transit:   msg   =   "ip   ttl   expired   transit"
case   ip_ttl_expired_reassem:   msg   =   "ip   ttl   expired   reassem"
case   ip_param_problem:   msg   =   "ip   param_problem"
case   ip_source_quench:   msg   =   "ip   source   quench"
case   ip_option_too_big:   msg   =   "ip   option   too_big"
case   ip_bad_destination:   msg   =   "ip   bad   destination"
case   ip_addr_deleted:   msg   =   "ip   addr   deleted"
case   ip_spec_mtu_change:   msg   =   "ip   spec   mtu   change"
case   ip_mtu_change:   msg   =   "ip   mtu_change"
case   ip_unload:   msg   =   "ip   unload"
case   ip_addr_added:   msg   =   "ip   addr   added"
case   ip_general_failure:   msg   =   "ip   general   failure"
case   ip_pending:   msg   =   "ip   pending"
case   ping_timeout:   msg   =   "ping   timeout"
case   else:   msg   =   "unknown   msg   returned"
end   select
 
getstatuscode   =   cstr(status)   &   "   [   "   &   msg   &   "   ]"
 
end   function
 
 
public   function   hibyte(byval   wparam   as   integer)
 
hibyte   =   wparam   \   &h100   and   &hff&
 
end   function
 
 
public   function   lobyte(byval   wparam   as   integer)
 
lobyte   =   wparam   and   &hff&
 
end   function
 
 
public   function   pingecho(szaddress   as   string,   echo   as   icmp_echo_reply)   as   long
 
dim   hport   as   long
dim   dwaddress   as   long
dim   sdatatosend   as   string
dim   iopt   as   long
 
sdatatosend   =   "echo   this"
dwaddress   =   addressstringtolong(szaddress)
 
call   socketsinitialize
hport   =   icmpcreatefile()
 
if   icmpsendecho(hport,   _
dwaddress,   _
sdatatosend,   _
len(sdatatosend),   _
0,   _
echo,   _
len(echo),   _
ping_timeout)   then
 
'the   ping   succeeded,
'.status   will   be   0
'.roundtriptime   is   the   time   in   ms   for
'   the   ping   to   complete,
'.data   is   the   data   returned   (null   terminated)
'.address   is   the   ip   address   that   actually   replied
'.datasize   is   the   size   of   the   string   in   .data
pingecho   =   echo.roundtriptime
else:   pingecho   =   echo.status   *   -1
end   if
 
call   icmpclosehandle(hport)
call   socketscleanup
 
end   function
 
 
function   addressstringtolong(byval   tmp   as   string)   as   long
 
dim   i   as   integer
dim   parts(1   to   4)   as   string
 
i   =   0
 
'we   have   to   extract   each   part   of   the
'123.456.789.123   string,   delimited   by
'a   period
while   instr(tmp,   ".")   >   0
i   =   i   +   1
parts(i)   =   mid(tmp,   1,   instr(tmp,   ".")   -   1)
tmp   =   mid(tmp,   instr(tmp,   ".")   +   1)
wend
 
i   =   i   +   1
parts(i)   =   tmp
 
if   i   <>   4   then
addressstringtolong   =   0
exit   function
end   if
 
'build   the   long   value   out   of   the
'hex   of   the   extracted   strings
addressstringtolong   =   val("&h"   &   right("00"   &   hex(parts(4)),   2)   &   _
right("00"   &   hex(parts(3)),   2)   &   _
right("00"   &   hex(parts(2)),   2)   &   _
right("00"   &   hex(parts(1)),   2))
 
end   function
 
 
public   function   socketscleanup()   as   boolean
 
dim   x   as   long
 
x   =   wsacleanup()
 
if   x   <>   0   then
msgbox   "windows   sockets   error   "   &   trim$(str$(x))   &   _
"   occurred   in   cleanup.",   vbexclamation
socketscleanup   =   false
else
socketscleanup   =   true
end   if
 
end   function
 
发表于:2008-02-03 17:45:1910楼 得分:0
接上贴

 
public   function   socketsinitialize()   as   boolean
 
dim   wsad   as   wsadata
dim   x   as   integer
dim   szlobyte   as   string,   szhibyte   as   string,   szbuf   as   string
 
x   =   wsastartup(ws_version_reqd,   wsad)
 
if   x   <>   0   then
msgbox   "windows   sockets   for   32   bit   windows   "   &   _
"environments   is   not   successfully   responding."
socketsinitialize   =   false
exit   function
end   if
 
if   lobyte(wsad.wversion)   <   ws_version_major   or   _
(lobyte(wsad.wversion)   =   ws_version_major   and   _
hibyte(wsad.wversion)   <   ws_version_minor)   then
 
szhibyte   =   trim$(str$(hibyte(wsad.wversion)))
szlobyte   =   trim$(str$(lobyte(wsad.wversion)))
szbuf   =   "windows   sockets   version   "   &   szlobyte   &   "."   &   szhibyte
szbuf   =   szbuf   &   "   is   not   supported   by   windows   "   &   _
"sockets   for   32   bit   windows   environments."
msgbox   szbuf,   vbexclamation
socketsinitialize   =   false
exit   function
 
end   if
 
if   wsad.wmaxsockets   <   min_sockets_reqd   then
szbuf   =   "this   application   requires   a   minimum   of   "   &   _
trim$(str$(min_sockets_reqd))   &   "   supported   sockets."
msgbox   szbuf,   vbexclamation
socketsinitialize   =   false
exit   function
end   if
 
socketsinitialize   =   true
 
end   function
 

public   function   pingip(byval   ipaddr   as   string)   as   long
dim   echo   as   icmp_echo_reply
pingip   =   pingecho(ipaddr,   echo)
end   function
发表于:2008-02-03 23:05:1211楼 得分:0
up
发表于:2008-02-04 09:16:1712楼 得分:0
shell   "ping   "   &   网址   &   "   > >   c:\temp.txt"
然后读c:\temp.txt内容即可。


快速检索

最新资讯
热门点击