C# serial port outgoing traffic sniffing - c#

I've been looking around quite alot for a way to sniff outgoing traffic on a serial port.
The reason I want to do that is to be able to sniff and decipher message Im sending from another app I have.
There are apps that allow sniffing on a serial port without blocking it from other apps (I usually use free serial port monitor).
Is there a way to do that with C#?
Thanks

Related

How to get remote ip address and port from active udp connection?

I'm working on a graphical windows application. So solutions on c++ and c# are prefered.
For my application, I need to get the remote address and port from active udp connection from a specific process.
I tried IP Helper API but the methods for UDP don't give remote address and port.
I've already see these posts Get Destination Ip/Port of active udp Connection? and Remote address of active UDP connections in Windows using IP Helper.
I understand why IP Helper can't do the job (udp is connectionless and need to capture packet) but I found nothing concrete how to accomplish that.
Have you a solution ready to use or something close to it?
As you have already discovered, UDP is connectionless, so the OS doesn't track remote party info, like it does for TCP. Unlike a TCP socket, a UDP socket can communicate with multiple remote parties at a time, where sendto() specifies a destination ip/port, and recvfrom() reports a sender's ip/port.
I understand why IP Helper can't do the job (udp is connectionless and need to capture packet) but I found nothing concrete how to accomplish that.
You need to use a packet capture library, such as libpcap, and manually keep track of the ips/ports of outgoing packets you see.

Is it possible to use UDP with Web Sockets instead of TCP

I have a C# desktop app and a C# Server console app.
The C# desktop client app uses WebSocket4Net and my C# server app uses Fleck.
Am I right in assuming that it uses TCP protocol. If so, can I get it to use UDP protocol?
The reason I asking this is because I read TCP is slower than UDP because TCP ensures order of packets.
I read this from this article:
Making Fast-Paced Multiplayer Networked Games is Hard
No, WebSockets are based on TCP which in turn is based on IP. UDP is also based on IP, but doesn't have anything to make sure the packets arrive in order or arrive at all. UDP just throws packets at a remote endpoint in the hope someone catches it. It's connectionless, so impossible to use UDP with WebSockets.

writing signals to serial port

I am trying to write data to a DMX receiver via USB to RS485 cable. I can see the correct data frames, but for the packet to follow the DMX protocol, I need a break and MAB signal. So my question is, is there a way to generate such signals? My thoughts were to write hi and lo signals with delays to the serial port but I have not found a way to do this in VS C#.
There is an example (though not in .NET but you can translate it) here:
How to control DmxSimple over serial
And use the SerialPort class to send the data down your cable

How to receive data over wifi router in C#

Hi I'm doing a research on wireless networks. I'm not good at C#. Normally, I use serial I/O to send data from Jennic JN5139's UART to PC via USB. I want to connect JN5139's UART output to a wireless router via a USB to Ethernet adaptor.
How can I read data which is sent to the router, and then send the data from the router to a computer over Wi-Fi? I don't even know where to start looking for a solution to this problem. Could anyone offer me a way to do this?
Assuming you have no control over the router, you can intercept the traffic outbound from the computer to the router via your Ethernet device. You can then capture the wireless traffic inbound to the computer from the wireless router using WireShark and a supported wireless NIC. Take a look here in the Wireshark Wiki for more detailed information on capture WLAN traffic and the caveats involved.
If you want to capture traffic programmatically with C# there are a number of frameworks available to you to use. Consider SharpPCap.
In order to have a serial port accessible over a network, you would need some sort of device server. I can highly recommend those from COMTROL and Digi, but there are also many cheaper versions out there.
Once the device is connected, it will be assigned an IP Address and Port. You can then connect to the serial port across the network using the TcpClient class which is a Stream in much the same way as a SerialPort class.
It also seems like Jennic has their own proprietary JenNET to Ethernet bridge. They may be able to provide further support or direction.

Port forwarding from C#

I would like to make a program in C# that would port forward a specific port from the router to the computer. Is this possible?
It is possible to forward a port using UPNP (assuming your device supports the technology) using NATUPnP 1.0 Type Library (NATUPNP.DLL) or a third party library like Mono.Nat.
If you want to do it without UPNP then it will be considerably harder since you will need to find what kind of message you will need to send to the device (router) to simulate a user adding a port.
For Mono.Nat you can find an example at UPNP port forwarding – The easy way
and for NATUPnP there is an example at .NET Framework: Communicate through NAT Router via UPnP (Universal Plug and Play)
No, it is not possible
Port forwarding is the task of your network device where all the other computers of a network are connected. Once the packet leaves the router, it has no control over it.
Further, unless you forward the port from router, there is no way for a computer in internal lan to get that packet and there is no question of forwarding at all.

Categories

Resources