aromberg
asked on
VB6 - Netstat code breaking under Windows Server 2003 SBS
Hello!
Here's my problem. I'm writing a program in VB6 that does the following: does a netstat output, ignores all listen sockets, and counts the amount of established sockets on port 27046, and dumps that value in a .csv. Problem is, none of the code examples I find online work on SBS2003. They work great on XP, but once I throw them on SBS, I get a vary of error messages. The one that pertains to this section of code is '6 - Overflow' The code is taken from http://www.ostrosoft.com/vb/projects/iphlpapi.asp, and modified accordingly. Even the authors code breaks... which is making me pull hairs!
Thanks for any help!
---snip---
Private Sub DoNetstat()
Open fileName For Append As #1
Dim pTcpTable As MIB_TCPTABLE
Dim pdwSize As Long
Dim bOrder As Long
Dim nRet As Long
Dim i As Integer, s As String
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat called (break here)" & vbCrLf
license = 0
nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
For i = 0 To pTcpTable.dwNumEntries - 1
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: in for i=" & i & vbCrLf
If pTcpTable.table(i).dwState - 1 <> MIB_TCP_STATE_LISTEN Then
frmdebug.Text1 = frmdebug.Text1 & c_ip(pTcpTable.table(i).dw LocalAddr) & ":" & _
c_port(pTcpTable.table(i). dwLocalPor t) & vbTab & _
c_ip(pTcpTable.table(i).dw RemoteAddr ) & ":" & _
c_port(pTcpTable.table(i). dwRemotePo rt) & vbTab & _
c_state(pTcpTable.table(i) .dwState - 1) & vbCrLf & "*************" & vbCrLf
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: after if, right before bot=" & vbCrLf
bot = c_port(pTcpTable.table(i). dwLocalPor t)
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: bot " & bot & vbCrLf
If (bot = 27046) Then
license = license + 1
Else
End If
End If
Next
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat finished.. writing file" & vbCrLf
Label5.Caption = license
Write #1, DateTime.Date$, DateTime.Time$, license
Close #1
frmdebug.Text1 = frmdebug.Text1 & "File written and closed\n" & vbCrLf
End Sub
---end snip--
Here's my problem. I'm writing a program in VB6 that does the following: does a netstat output, ignores all listen sockets, and counts the amount of established sockets on port 27046, and dumps that value in a .csv. Problem is, none of the code examples I find online work on SBS2003. They work great on XP, but once I throw them on SBS, I get a vary of error messages. The one that pertains to this section of code is '6 - Overflow' The code is taken from http://www.ostrosoft.com/vb/projects/iphlpapi.asp, and modified accordingly. Even the authors code breaks... which is making me pull hairs!
Thanks for any help!
---snip---
Private Sub DoNetstat()
Open fileName For Append As #1
Dim pTcpTable As MIB_TCPTABLE
Dim pdwSize As Long
Dim bOrder As Long
Dim nRet As Long
Dim i As Integer, s As String
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat called (break here)" & vbCrLf
license = 0
nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
nRet = GetTcpTable(pTcpTable, pdwSize, bOrder)
For i = 0 To pTcpTable.dwNumEntries - 1
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: in for i=" & i & vbCrLf
If pTcpTable.table(i).dwState
frmdebug.Text1 = frmdebug.Text1 & c_ip(pTcpTable.table(i).dw
c_port(pTcpTable.table(i).
c_ip(pTcpTable.table(i).dw
c_port(pTcpTable.table(i).
c_state(pTcpTable.table(i)
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: after if, right before bot=" & vbCrLf
bot = c_port(pTcpTable.table(i).
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat: bot " & bot & vbCrLf
If (bot = 27046) Then
license = license + 1
Else
End If
End If
Next
frmdebug.Text1 = frmdebug.Text1 & "DoNetStat finished.. writing file" & vbCrLf
Label5.Caption = license
Write #1, DateTime.Date$, DateTime.Time$, license
Close #1
frmdebug.Text1 = frmdebug.Text1 & "File written and closed\n" & vbCrLf
End Sub
---end snip--
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a bunch!