Para 'Net'
Aca te dejo un ejemplo que usa las apis que mencione arriba.
PSCExample
Para 'Netstat'
Solo un Modulo.
P.D.: Es BlackZeroX no "BlackZero"
Saludos, Dulces Lunas
Aca te dejo un ejemplo que usa las apis que mencione arriba.
PSCExample
Para 'Netstat'
Solo un Modulo.
Código (vb) [Seleccionar]
Option Explicit
Enum StadosPort
UNKNOWN = 0
CLOSED = 1
LISTENING = 2
SYN_SENT = 3
SYN_RCVD = 4
ESTABLISHED = 5
FIN_WAIT1 = 6
FIN_WAIT2 = 7
CLOSE_WAIT = 8
CLOSING = 9
LAST_ACK = 10
TIME_WAIT = 11
DELETE_TCB = 12
End Enum
Type MIB_TCPROW
dwState As StadosPort
dwLocalAddr As Long
dwLocalPort As Long
dwRemoteAddr As Long
dwRemotePort As Long
End Type
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 'This is used to close an open port.
Public Declare Function ntohs Lib "WSOCK32.DLL" (ByVal netshort As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
'Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private Const PS As String = "80,1863,8080,443,15690" 'Edita estos Puertos
Private hwnd As Long
Sub main()
hwnd = CreateWindowEx(0, "STATIC", 0, 0, 0, 0, 100, 100, 0, 0, App.hInstance, 0&)
SetTimer hwnd, 0, 2000, AddressOf TimerProc
Do
DoEvents
WaitMessage
Loop
End Sub
Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Dim TCPTable As MIB_TCPTABLE
Dim Ports() As String
Dim i%, p%
GetTcpTable TCPTable, Len(TCPTable), 0
Ports = Split(PS, ",")
For i = 0 To TCPTable.dwNumEntries - 1
For p = 0 To UBound(Ports) - 1
If Ports(p) = ntohs(TCPTable.table(i).dwRemotePort) Then
GoTo Salto:
ElseIf (p = Val(UBound(Ports) - 1)) Then
TCPTable.table(i).dwState = DELETE_TCB
SetTcpEntry TCPTable.table(i)
Debug.Print ntohs(TCPTable.table(i).dwRemotePort)
GoTo Salto:
End If
Next p
Salto:
Next i
End Sub
P.D.: Es BlackZeroX no "BlackZero"
Saludos, Dulces Lunas