인터넷 연결이 있는지 여부를 테스트하는 데 사용되는 vb6 코드가 있습니다. Google DNS를 사용하여 확인합니다. Windows XP에서 정상적으로 작동합니다. 그러나 Windows 8의 경우 인터넷이 연결되어 있거나 연결되어 있지 않으면 항상 성공을 반환합니다 (인터넷에 연결되어 있음). 내가 의 사용이 아래 아래인터넷 연결을 확인하면 Windows 8에서 오류가 발생합니다.
Private Function CheckForInternet(ByVal ServerIP As String, ByRef IsTimedOut As Boolean) A
s Boolean
On Error GoTo CheckForInternet_EH
Dim Reply As ICMP_ECHO_REPLY
Dim lngSuccess As Long
Dim strIPAddress As String
Dim a As String
Dim startTimer As Single
Dim EndTimer As Single
Const Time_out_in_ms As Integer = 1000
'Get the sockets ready.
If SocketsInitialize() Then
'Address to ping
strIPAddress = ServerIP
'Ping the IP that is passing the address and get a reply.
lngSuccess = ping(strIPAddress, Time_out_in_ms, Reply)
'Clean up the sockets.
SocketsCleanup
''Return Value
If lngSuccess = ICMP_SUCCESS Then
CheckForInternet = True
ElseIf lngSuccess = ICMP_STATUS_REQUEST_TIMED_OUT Then
IsTimedOut = True
End If
'Else
' 'Winsock error failure, initializing the sockets.
' Debug.Print WINSOCK_ERROR
End If
Exit Function
CheckForInternet_EH:
Call msglog(Err.Description & Space(10) & "CheckForInternet", False)
End Function
코딩의 일부입니다 그리고 만드는 중이라서 그것은 코딩의 일부입니다 핑 절차
Public Function ping(ByVal sAddress As String, ByVal time_out As Long, Reply As ICMP_ECHO_REPLY) As Long
On Error GoTo ping_EH
Dim hIcmp As Long
Dim lAddress As Long
Dim lTimeOut As Long
Dim StringToSend As String
'Short string of data to send
StringToSend = "hello"
'ICMP (ping) timeout
lTimeOut = time_out ''ms
'Convert string address to a long representation.
lAddress = inet_addr(sAddress)
If (lAddress <> -1) And (lAddress <> 0) Then
'Create the handle for ICMP requests.
hIcmp = IcmpCreateFile()
If hIcmp Then
'Ping the destination IP address.
Call IcmpSendEcho(hIcmp, lAddress, StringToSend, Len(StringToSend), 0, Reply, Len(Reply), lTimeOut)
'Reply status
ping = Reply.Status
'Close the Icmp handle.
IcmpCloseHandle hIcmp
Else
'Debug.Print "failure opening icmp handle."
ping = -1
End If
Else
ping = -1
End If
Exit Function
ping_EH:
Call msglog(Err.Description & Space(10) & "ping", False)
End Function
이다 (나는의 DNS 제대로 같은 sAddress로 매개 변수를 전달합니까 구글 등). 지금 나는 인터넷 연결이 Windows XP에서있을 때 관찰했다. Reply.Status는 성공을 위해 0을 반환한다 .Same은 Windows 8의 경우이기도하다. 그러나 인터넷 연결이 없다면 xp가 반환한다. ping 값은 11003 (인터넷 연결이 없음을 의미). 그러나 Windows 8에서는 여전히 성공을 위해 0을 반환합니다. 또한 링크에 IcmpSendEcho IP_OPTION_INFORMATION 64 비트 PC를위한 다른 등 등 :
그래서 나는 그것이 잘못된 값을 내가 정의을 반환 IcmpSendEcho 기능 문제 또한 다음
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
'This structure describes the options that will be included in the header of an IP packet.
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcetcpip/htm/cerefIP_OPTION_INFORMATION.asp
Private Type IP_OPTION_INFORMATION
Ttl As Byte
Tos As Byte
Flags As Byte
OptionsSize As Byte
OptionsData As Long
End Type
'This structure describes the data that is returned in response to an echo request.
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/htm/_wcesdk_icmp_echo_reply.asp
Public Type ICMP_ECHO_REPLY
address As Long
Status As Long
RoundTripTime As Long
DataSize As Long
Reserved As Integer
ptrData As Long
Options As IP_OPTION_INFORMATION
Data As String * 250
End Type
힌트라고 생각합니다 .. 링크에서 "반향 요청에 대한 응답을 보유하는 버퍼"와 같이 언급됩니다. 반환시 버퍼에는 ICMP_ECHO_REPLY 구조체의 배열과 그 뒤에 응답에 대한 옵션 및 데이터가 포함됩니다. 하나 이상의 ICMP_ECHO_REPLY 구조체 pluc를 보유 s RequestSize 바이트의 데이터. " 그래서 나는 지금 ICMP_ECHO_REPLY32 및 IP_OPTION_INFORMATION32을 선언하는 방법을 원하는 (나는 단지 ICMP_ECHO_REPLY 사용하고 IP_OPTION_INFORMATION) 그래서 나는이 두 가지 간단한 기능했던 인터넷 연결을 확인하려면 문제