How to bring down a socket on a windows machine? - windows

I have a application which I suspects to get into problems because network nodes closes its sockets to various other servers it communicates to.
I would like to mimic that behaviour by shutting down one or severel connections that can be seen in netstat.
I'm not an expert in networking on OS level, so this question may be stupid, if so do you have any other suggestion on how to mimic the situation?

Before attempting to simulate the problem, you can diagnose the situation with certainty by using Wireshark or, on *nix, tcpdump. You should be able to capture the traffic and observer whether one of the server(s) is sending you a RST or not.
If you are receiving RST then this may be due to the servers themselves (time-outing and closing the connection while waiting for you to send them a response or data, or closing the connection because of server bugs or load limits), to your ISP's network equipment, or to your own network equipment (e.g. your wireless link going up and down.)
Disconnecting your router, network cable or wireless interface can simulate to various degrees connection issues that you can encounter at any time when talking to your servers. Disconnecting your PC's network cable should simulate a forceful closing of the connection with RST, whereas disconnecting a cable between you and the internet, but not the cable that directly connects your PC (e.g. disconnecting the cable between your router and your cable/DSL modem, or disconnecting the cable/DSL modem from the cable company's cable/telco's wall jack) will allow you to simulate timeout conditions.

You can use TCP View. You can view all the connections from your machine to another, or within the same machine. You can close a connection, thus breaking the connection.

Related

How to resolve the problem of P2P Connection for 3 layers of NAT

Currently, I am doing a project which remoting a toy car under the cellular network which is a P2P connection.
I required to use PC (WiFi Connection) to control the toy car (Data hotspot connection) and transfer packet by using UDP.
It seems like have some issue within it, first for all will be the CGNAT problem. I know we can use the UDP hole punching but it is hard for me do to this due to I am weak knowledge on this area.
I would like to ask is there any way still can be implemented for the P2P connection if a VPN is available?
check out ZeroTier
ZeroTier combines the capabilities of VPN and SD-WAN, simplifying network management.
Emulates Layer 2 Ethernet with multipath, multicast, and bridging capabilities.
ZeroTier provides network control and P2P functionality.
Use ZeroTier to create products which run on their own decentralized networks.
Access your desktop, NAS, and other devices from anywhere

From WiFi to Cellular 3/4G on ESP32

I am building a project utilizing Wifi on the ESP32 module. Using RTOS, I am running a web server on 1 core and a web client on another core. This works very well and I can access the web server remotely via my browser and the WiFi provided IP address. The Web client reads some sensors and sends the data via WiFi to my database. All good and everything works as desired.
Now I need to do the next step and move beyond the reach of the WiFi and reproduce the same result via 3/4G cellular. I looked at the "easy" solution to use an industrial 3/4G WiFi router and simply keep what I have. Cost of these "industrial" type routers are on the high side, where as 3/4G module which also include a GPS chip are around half or less. Problem is that I cannot get my head around how I will "replace" my current WiFi functionality with one of these modules. The modules seems to expect you to connect via serial (rs232) and using modem AT commands establish a connection to the internet. Question is, after connecting to the internet, how do you continue to have "network functionality" same as with the built-in WiFi? Is there some library that will do ethernet over the serial port? Can I still have the WiFi and the "serial ethernet" running at the same time or switch between the two?
Thanks!

Developing a Mac OSX Network Driver for a Serial Port AT Command Based Modem

First allow me to say that I don't have any experience developing drivers for OSX, nor drivers for Windows. So, there are a lot of things that I don't understand about how drivers work; I'm sure it'll be evident in my question.
I have a modem that is able to open and close TCP/UDP sockets using AT commands. I would like to create some kind of program (kernel extension? driver?) that implements a network driver, converting the network interface calls into AT command serial messages.
That's the basic jist of it. I'm essentially asking if anybody can point me in the right direction / give me a high level overview of how they would approach it and what Apple guides to focus on.
The XNU networking stack -- like most network stacks -- expects network devices to send and receive IP packets directly. It isn't tooled to work with network devices that handle part of the network stack (like TCP or UDP) internally -- it won't be possible to implement a network driver which uses this device.
You might have more luck exposing this device as a SOCKS proxy. You will need to write a userspace daemon which listens on a TCP port on localhost (on the computer) and relays traffic to the serial device; once that's done, you can set the computer to use that device as a SOCKS proxy in the Networking control panel.
(As an aside: most devices that implement this type of interface have a very low limit on the number of open sockets -- often fewer than 10. They're unlikely to be able to handle the network load generated by a desktop OS.)

Sockets leaked in windows not shown in netstat and tcpview

Is it possible that windows leaks sockets connection and these sockets are not shown in tcpview and netstat?
After running a few applications that perform many network connections, my windows machine enters a state in whitch it in not able to open any new socket connection. Even to itself (localhosts).
For example, telnet to a local application failed because windows can't create new sockets.
Closing and restarting the network applications does not helps. Only full windows restart solves the problem.
netstat (& tcpview) indicates that there are only some dozens of connections.
Thanks for your help.
No, it is not possible for those apps to miss leaked connections. Something else is going on. Maybe you are not looking at their detailed views, like seeing closed sockets that are in TIME_WAIT state. If you cannot open new socket connections, you mostly likely are encountering port exhaustion. Wait some time for ports to time out and become available again. Or stop wasting ports in the first place.

Simulating a network down to particular process

I am trying to simulate a scenario where connection to the server of one process is down while the connection to another server is up. Just pulling the network cable won't work in my case since I need another process connection to stay up.
Is there any tool for this kind of job? I am on Windows. Thanks!
There's a few layers which you can simulate this at. The easiest would be if your two servers listen on two distinct TCP ports. In that case, you could run two tcp proxies, and stop/pause one when you want to simulate a failure. For Windows I would suggest using tcpTrace to do this.
Another option would be to have the two servers bound to two virtual NICs, which are bridged to the physical NIC. Of course if you have two physical NICs, you could bind each server process to a different physical NIC.
At a lower level, you can ran a WAN simulator. Most simulators allow you to impair specific types of traffic or specific ports. One such simulator is Packetstorm.
One other method which I would suggest is attaching a debugger to one process, and halting all threads on the process with the debugger. Often, a process doesn't die, but gets stuck in garbage collection, or in a loop. As the sockets don't close, many 'high availability' solutions won't automatically failover.
One approach would be to mock the relevant network connection code for the purposes of testing. In this case you would probably want to mock it returning whatever it usually would if the connection was down.
A poor man's approach if you can use sleep/hibernate mode on your machine :
Set an Outbound rule in the Windows Firewall to disallow connection for a particular Program.
Already connected sockets stay connected: put the machine in sleep/hibernate mode for a brief moment to force those sockets to disconnect.
When the system is restored, the program cannot establish new connections.
New connections are made possible as soon as you disable the firewall rule.
Note that it does not simulate network outage because each connection fails immediately with an permission error. But it prevents a process to establish connections.

Resources