Garry
October 20th, 1999, 08:07 AM
How do I ping a computer from a Nt machine. I want to get a response back and I have to run this application every half and hour to test if the server is running.
|
Click to See Complete Forum and Search --> : ping Garry October 20th, 1999, 08:07 AM How do I ping a computer from a Nt machine. I want to get a response back and I have to run this application every half and hour to test if the server is running. Aaron Young October 20th, 1999, 02:35 PM Try this Example I put together using the Winsock APIs: For this Example you need a Form with 2 Textboxes and a CommandButton.. private Const MAX_WSADescription = 256 private Const MAX_WSASYSStatus = 128 private Const WS_VERSION_REQD = &H101 private Type HOSTENT hName as Long hAliases as Long hAddrType as Integer hLen as Integer hAddrList as Long 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 Integer wMaxUDPDG as Integer dwVendorInfo as Long End Type private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest as Any, byval hpvSource as Long, byval cbCopy as Long) private Declare Function gethostbyname Lib "WSOCK32.DLL" (byval szHost as string) 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 Function GetIPAddress(byval sHost as string) as string Dim I as Integer Dim lHost as Long Dim lIP as Long Dim sIP() as Byte Dim sFullIP as string Dim tHost as HOSTENT Dim tSocket as WSADATA 'Establish an Open Socket If WSAStartup(WS_VERSION_REQD, tSocket) <> 0 then Exit Function 'Attempt to Locate Data pointer for Specified Host Name lHost = gethostbyname(sHost) If lHost = 0 then MsgBox "Unable to Locate Host." else 'get the Host Info CopyMemory tHost, lHost, len(tHost) 'Extract the Address of the IP Data from the Addresslist Pointer CopyMemory lIP, tHost.hAddrList, len(tHost.hAddrList) 'Build a Tempory array to hold the IP Values ReDim sIP(tHost.hLen - 1) 'Copy the IP Values into the Array CopyMemory sIP(0), lIP, tHost.hLen 'Build the IP Address for I = 0 to tHost.hLen - 1 sFullIP = sFullIP & "." & sIP(I) next 'Trim of the Preceeding Period GetIPAddress = mid(sFullIP, 2) End If 'Close up the Socket Call WSACleanup End Function private Sub Command1_Click() Text2 = GetIPAddress(Text1) End Sub Aaron Young Analyst Programmer adyoung@win.bright.net aarony@redwingsoftware.com Dr_Michael October 27th, 2000, 07:05 AM I used this useful code. It works and returns the IP address of a specific server giving as input the server name (eg www.yahoo.com) The problem is that in a specific situation where the server was "down" (I mean it was not connected to Internet because of a network damage), the program continued to find the server and giving the right IP. How is it possible? Are there various levels of ping? And something important: Trying to ping with this code, it resolved the right IP address, but at exactly the same time, I tried manually to ping by msdos prompt and the server not found (as expected). What's going on??? Michael Vlastos Automation Engineer Intracom, Research & Development Division Development Programmes Department Athens, Greece TCartwright October 27th, 2000, 10:01 AM All ping is telling you that is that the server's NIC is responding to ICMP requests. That does not mean that the web site is necessarily working. The web site is listening over a socket (typically port 80) and just because you can't load the web page does not mean the server is down. And just because ping is working does not mean the web site is up. Bottom Line : If ping returns the server is powered up, and configured to return ICMP. It does not mean that anything else is working on the server besides the NIC.... Tim Cartwright 'Will write code for food. Sr Systems Architect - Information Systems Splitrock Services Inc. Dr_Michael October 28th, 2000, 04:49 AM Ok I understood but you missed a point: I said that in the same time, I was pinging manually (by MSDOS prompt) and taking NO reply, but besides the application with the code posted here, it's pinging was giving reply!!! How is it possible? And most of all, how can I ping the server correctly, as exactly can be done by MSDOS prompt? Michael Vlastos Automation Engineer Intracom, Research & Development Division Development Programmes Department Athens, Greece codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |