I need a hand debugging my VB program

iamwiz82

Lifer
Jan 10, 2001
30,772
13
81
Here is the code:

For n = 3 To 9

k = CStr(n)
ComputerName = "A"
ComputerName = "RHW" + "00" + k
MsgBox "checking computer " & ComputerName
HostName = ComputerName
Dim hFile As Long, lpWSAdata As WSAdata
Dim hHostent As Hostent, AddrList As Long
Dim Address As Long, rIP As String
Dim OptInfo As IP_OPTION_INFORMATION
Dim EchoReply As IP_ECHO_REPLY
Call WSAStartup(&H101, lpWSAdata)


If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4
End If
hFile = IcmpCreateFile()


If hFile = 0 Then
MsgBox "Unable to Create File Handle"
Exit Sub
End If


OptInfo.TTL = 255


If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000) Then rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3)) Else: MsgBox "Timeout"


If EchoReply.Status = 0 Then
MsgBox "Reply from " + HostName + " (" + rIP + ") recieved after " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
Else
MsgBox "Failure ..."
End If


Call IcmpCloseHandle(hFile)
Call WSACleanup

It is a hacked together program grabbed from some script sites. The goal is to go through a list of numbers corrisponding to computer names, ping the name, determine if the connection is active, and tehn grab the serial number out of the BIOS.

My issue is that one computer (7) does not exist on the network, nor has it. When the program tried to grab the IP address, it cannot find one, so it reverts to the last IP address (of 6's), pings it and finds it. Now it tries to grab the serial out of 7's BIOS but 7 doesn't exist, so it crashes. Anyone have any ideas on what to do?
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
I do not understand VB, however from a theory viewpoint, are you initializing all variables prior to each attempt to access a system.

If not, then failures may leave old data lying around, which it sounds like you are picking up and trying to use.
 

Apathetic

Platinum Member
Dec 23, 2002
2,587
6
81
I didn't have access to VB, so this may or may not be completely correct, but give it a try.

Also, I have no idea if you really need to call WSAStartup/WSACleanup from within your loop.

Dave


Dim hFile As Long, lpWSAdata As WSAdata
Dim hHostent As Hostent, AddrList As Long
Dim Address As Long, rIP As String
Dim OptInfo As IP_OPTION_INFORMATION
Dim EchoReply As IP_ECHO_REPLY
Dim HostName as String
Dim n as Integer

For n = 3 To 9
HostName = "RHW" &amp; "00" &amp; CStr(k)
MsgBox "Checking computer " &amp; HostName
Call WSAStartup(&amp;H101, lpWSAdata)

If GetHostByName(HostName + String(64 - Len(HostName), 0)) <> SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(HostName + String(64 - Len(HostName), 0)), Len(hHostent)
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4

hFile = IcmpCreateFile()
If hFile = 0 Then
MsgBox "Unable to Create File Handle"
Exit Sub
End If

OptInfo.TTL = 255

If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000) Then
rIP = CStr(EchoReply.Address(0)) + "." + CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." + CStr(EchoReply.Address(3))
If EchoReply.Status = 0 Then
MsgBox "Reply from " + HostName + " (" + rIP + ") recieved after " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
Else
MsgBox "Failure ..."
End If
Else
MsgBox "Timeout checking " &amp; HostName
End If

Call IcmpCloseHandle(hFile)
End If

Call WSACleanup
Next