J
Jm
Hi All
I recently got some help with code conversion that i used in vb6 to block a
specific tcp port. The code runs under a timer and is run on a very low tick
count (Meaning it happens constantly). Unfortunately the code appears to do
nothing ? This is the converted code
Public Structure MIB_TCPROW
Public dwState As Integer
Public dwLocalAddr As Integer
Public dwLocalPort As Integer
Public dwRemoteAddr As Integer
Public dwRemotePort As Integer
End Structure
Public Structure MIB_TCPTABLE
Public dwNumEntries As Integer
Public table() As MIB_TCPROW
End Structure
Public MIB_TABLE As MIB_TCPTABLE
Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable
As MIB_TCPTABLE, ByRef pdwSize As Integer, ByVal bOrder As Integer) As
Integer
Public Declare Function SetTcpEntry Lib "IPhlpAPI" (ByVal pTcpRow As
MIB_TCPROW) As Integer
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As
Integer) As Integer
Public Sub BlockPort()
Dim LTmp As Integer
Dim x As Integer, i As Integer, n As Integer
Dim RemP As String
Dim tcpt As MIB_TCPTABLE
' LTmp = Len(MIB_TCPTABLE)
LTmp = MIB_TABLE.ToString.Length
GetTcpTable(tcpt, LTmp, 0)
x = tcpt.dwNumEntries
For i = 0 To tcpt.dwNumEntries - 1
RemP = ntohs(tcpt.table(i).dwRemotePort)
If RemP = "8080" And tcpt.table(i).dwState <> 2 Then
tcpt.table(i).dwState = 12
SetTcpEntry(tcpt.table(i))
End If
Next i
End Sub
****
This is the original vb6 code which ran fine
****
Public Type MIB_TCPROW
dwState As Long
dwLocalAddr As Long
dwLocalPort As Long
dwRemoteAddr As Long
dwRemotePort As Long
End Type
Public Type MIB_TCPTABLE
dwNumEntries As Long
table(100) As MIB_TCPROW
End Type
Public MIB_TCPTABLE As MIB_TCPTABLE
Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable As
MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
Public Declare Function SetTcpEntry Lib "IPhlpAPI" (pTcpRow As MIB_TCPROW)
As Long
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As Long) As
Long
Public Sub BlockPort
Dim LTmp As Long
Dim x As Integer, i As Integer, n As Integer
Dim RemP As String
Dim tcpt As MIB_TCPTABLE
LTmp = Len(MIB_TCPTABLE)
GetTcpTable tcpt, LTmp, 0
x = tcpt.dwNumEntries
For i = 0 To tcpt.dwNumEntries - 1
RemP = ntohs(tcpt.table(i).dwRemotePort)
If RemP = "8080" And tcpt.table(i).dwState <> 2 Then
tcpt.table(i).dwState = 12
SetTcpEntry tcpt.table(i)
End If
Next i
End Sub
****
Can anybody see anything obviously wrong with the code conversion ? If not,
is there another way i can block tcp traffic on a specific port. Basically
im trying to block internet access. Any help is greatly appreciated
Thanks
I recently got some help with code conversion that i used in vb6 to block a
specific tcp port. The code runs under a timer and is run on a very low tick
count (Meaning it happens constantly). Unfortunately the code appears to do
nothing ? This is the converted code
Public Structure MIB_TCPROW
Public dwState As Integer
Public dwLocalAddr As Integer
Public dwLocalPort As Integer
Public dwRemoteAddr As Integer
Public dwRemotePort As Integer
End Structure
Public Structure MIB_TCPTABLE
Public dwNumEntries As Integer
Public table() As MIB_TCPROW
End Structure
Public MIB_TABLE As MIB_TCPTABLE
Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable
As MIB_TCPTABLE, ByRef pdwSize As Integer, ByVal bOrder As Integer) As
Integer
Public Declare Function SetTcpEntry Lib "IPhlpAPI" (ByVal pTcpRow As
MIB_TCPROW) As Integer
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As
Integer) As Integer
Public Sub BlockPort()
Dim LTmp As Integer
Dim x As Integer, i As Integer, n As Integer
Dim RemP As String
Dim tcpt As MIB_TCPTABLE
' LTmp = Len(MIB_TCPTABLE)
LTmp = MIB_TABLE.ToString.Length
GetTcpTable(tcpt, LTmp, 0)
x = tcpt.dwNumEntries
For i = 0 To tcpt.dwNumEntries - 1
RemP = ntohs(tcpt.table(i).dwRemotePort)
If RemP = "8080" And tcpt.table(i).dwState <> 2 Then
tcpt.table(i).dwState = 12
SetTcpEntry(tcpt.table(i))
End If
Next i
End Sub
****
This is the original vb6 code which ran fine
****
Public Type MIB_TCPROW
dwState As Long
dwLocalAddr As Long
dwLocalPort As Long
dwRemoteAddr As Long
dwRemotePort As Long
End Type
Public Type MIB_TCPTABLE
dwNumEntries As Long
table(100) As MIB_TCPROW
End Type
Public MIB_TCPTABLE As MIB_TCPTABLE
Public Declare Function GetTcpTable Lib "iphlpapi.dll" (ByRef pTcpTable As
MIB_TCPTABLE, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
Public Declare Function SetTcpEntry Lib "IPhlpAPI" (pTcpRow As MIB_TCPROW)
As Long
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As Long) As
Long
Public Sub BlockPort
Dim LTmp As Long
Dim x As Integer, i As Integer, n As Integer
Dim RemP As String
Dim tcpt As MIB_TCPTABLE
LTmp = Len(MIB_TCPTABLE)
GetTcpTable tcpt, LTmp, 0
x = tcpt.dwNumEntries
For i = 0 To tcpt.dwNumEntries - 1
RemP = ntohs(tcpt.table(i).dwRemotePort)
If RemP = "8080" And tcpt.table(i).dwState <> 2 Then
tcpt.table(i).dwState = 12
SetTcpEntry tcpt.table(i)
End If
Next i
End Sub
****
Can anybody see anything obviously wrong with the code conversion ? If not,
is there another way i can block tcp traffic on a specific port. Basically
im trying to block internet access. Any help is greatly appreciated
Thanks