vb中使用telnet 或ping
vb中使用telnet 或ping ,请问将显示结果保存到temp.txt中?
[解决办法]
'ping的Global PortDone As IntegerGlobal OnPort As LongPublic Const WSA_DESCRIPTIONLEN = 256Public Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1Public Const WSA_SYS_STATUS_LEN = 128Public Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1Type Inet_address Byte4 As String * 1 Byte3 As String * 1 Byte2 As String * 1 Byte1 As String * 1 End TypeType WSAdata wVersion As Integer wHighVersion As Integer szDescription(0 To 255) As Byte szSystemStatus(0 To 128) As Byte iMaxSockets As Integer iMaxUdpDg As Integer lpVendorInfo As Long End TypeType Hostent h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End TypeType IP_OPTION_INFORMATION TTL As Byte Tos As Byte flags As Byte OptionsSize As Long OptionsData As String * 128 End TypeType IP_ECHO_REPLY Address(0 To 3) As Byte Status As Long RoundTripTime As Long DataSize As Integer Reserved As Integer Data As Long Options As IP_OPTION_INFORMATION End Type Public pIPe As IP_ECHO_REPLY Public pIPe2 As IP_ECHO_REPLY Public pIPe3 As IP_ECHO_REPLY Public pIPo As IP_OPTION_INFORMATION Public pIPo2 As IP_OPTION_INFORMATION Public pIPo3 As IP_OPTION_INFORMATION Public IPLong As Inet_address Public IPLong2 As Inet_address Public IPLong3 As Inet_address Public IPLong4 As Inet_address Public IPLong5 As Inet_address Public IPLong6 As Inet_address Public IPLong7 As Inet_address Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired&, lpWSAData As WSAdata) As LongPublic Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Long, ByVal DestAddress As Long, _ ByVal RequestData As String, ByVal RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION, _ ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Long, ByVal timeout As Long) As BooleanDeclare Function gethostname Lib "wsock32.dll" (ByVal hostname$, HostLen&) As LongDeclare Function gethostbyname& Lib "wsock32.dll" (ByVal hostname$)Declare Function WSAGetLastError Lib "wsock32.dll" () As LongDeclare Function WSACleanup Lib "wsock32.dll" () As LongDeclare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)Public Declare Function IcmpCreateFile Lib "ICMP.dll" () As LongPublic Declare Function IcmpCloseHandle Lib "ICMP.dll" (ByVal HANDLE As Long) As BooleanFunction ScanPort(thePort As Long, ws1 As Winsock) As BooleanScanPort = FalseOn Error GoTo gotportws1.Closews1.LocalPort = thePortws1.ListenPause 0.1ws1.CloseExit Functiongotport:If Err.Number = 10048 Then ScanPort = TrueEnd IfEnd FunctionSub Pause(Interval)'Pauses for a given time Dim Current Current = Timer Do While Timer - Current < Val(Interval) DoEvents LoopEnd Sub