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).dwLocalAddr) & ":" & _
        c_port(pTcpTable.table(i).dwLocalPort) & vbTab & _
        c_ip(pTcpTable.table(i).dwRemoteAddr) & ":" & _
        c_port(pTcpTable.table(i).dwRemotePort) & 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).dwLocalPort)
        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--
LVL 4
arombergAsked:
Who is Participating?
 
inthedarkCommented:
The problem is in the c_Port function

Function c_port(s) As Long
    c_port = CLng(Asc(Mid(s, 1, 1))) * clng(256) + CLng(Asc(Mid(s, 2, 1)))
End Function


Also you need to make sure output is a multiline box.

Hope this helkps:~)
0
 
arombergAuthor Commented:
Thanks!  That's what I needed for the most part... the next problem, which I'll detail here... was that the index array was too small... which caused a "9 - Subscript out of bounds error", so I had to go into my module and change the line that said 'table(100) As MIB_TCPROW   'array of TCP connections' to 'table(250) As MIB_TCPROW   'array of TCP connections'.

Thanks a bunch!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.