473,379 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

VB6 - VBNET Code Conversion - TCP Port Block

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
Nov 21 '05 #1
0 2176

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
28
by: wwj | last post by:
void main() { char* p="Hello"; printf("%s",p); *p='w'; printf("%s",p); }
2
by: K.M Jr | last post by:
Hi group, I usually don't code in C. I happened to write a piece of code that parses an input string of the form "host_name:XXXX" into host_name and XXXX. I would request the group to give me...
6
by: JustinC | last post by:
Does anyone know of a way, using C#, to programmatically block a Windows port? I've looked into some low level solutions like NDIS, but am hoping to find something that uses C#. Any help would be...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
7
by: R.A.M. | last post by:
Hello I have a question to .NET programmers about code conversion from VB6 to C#.NET: is it possible? how much work must be performed manually? Thank you very much for your answers. /RAM/ PS. By...
9
by: Sayudh27 | last post by:
Hi all, I am a relatively new programmer in C++...I need to write a code that performs multicasting as well as returns the data-packets in a decompressed form.Data-receipt seems to work...
20
by: simple25 | last post by:
I've been looking through sites to see if anyone could provide the correct steps to block port 1434, which is a MSSQL port. NOBODY and I mean NOBODY was smart enough to give a clear and simple...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.