I've released the source of my program btw, you can check it on Gitorious.
Especially
-
module_declaration.bas :
You must be registered to see links
-
module_disconnect.bas :
You must be registered to see links
As you can see the first one imports 3 functions from the Windows DLLs :
-
GetTcpTable from iphlpapi.dll : fetch the TCP connections table from the system IP stack
-
SetTcpEntry from iphlpapi.dll : changes a connection state
-
ntohs from wsock32.dll
Network TO Host Short) changes the byte order of an integer from network order to host order
and declares 3 types :
-
MIB_TCP_STATE : state of the TCP connection)
-
MIB_TCPROW : a line inside the TCP table)
-
MIB_TCPTABLE : the whole TCP table
The second one declares 2 functions :
-
ip_to_human : converts an ip from it's integer form to the w.x.y.z format
-
disconnect(ip) : disconnects a w.x.y.z ip
disconnect is very simple. It :
- fetches the TCP table from the IP stack (get_tcp_table)
- for each entry of the table, it :
--- converts the port to host byte order
--- converts the IP to w.x.y.z format
--- compares the table ip with the argument ip
--- compares the port with the argument port (here it's a configuration variable, but you can easily edit the function to work this way: disconnect(ip, port))
--- if both match, changes the state of the connection to
DELETE_TCB and set it (set_tcp_entry).
When you set the connection to this state, it sends a TCP packet to the client with the
RST (reset) flag set, and closes the connection whether or not the client acknowledges. It forces the client disconnection.
You'll also notice that the function uses only API functions and basic types, and no fancy VB6 built-in routine. Which means you can easly port this to another programming language that can import functions from the Windows DLLs
.