Sending TCP Packets through IP Address - c#

I know you can send UDP, HTTP, and TCP packets in java to a specific IP address. Since i'm learning c# i decided to make a Low Orbit Ion Cannon. Basically its used for stress testing network. So i'm kinda curious is their anyway to send TCP packets in c#. Could you give me some code examples? I tried to look online but couldn't find anything.

I would have a look at http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=vs.110).aspx for an introduction of what C# can do for you using a socket. And http://www.csharp-examples.net/socket-send-receive/ has an example of send and receive using a socket.

Related

Is an open TCP Port in C# secure?

I am sorry, this is kind of a noob question, but I don't get how ports work.
I think that when I open a tcp port in C# via the TcpListener on the server, anyone can connect to it. However, I only want my application client to connect to the port and send my predefined packets. Would it be possible for any person to connect to the port and send data that might harm my computer? Or is it just possible to send random data that is then just wrongly interpreted by my packet handlers?
I hope I could communicate my question clearly. Thanks in advance
Securing a port is generally a function of the operating system or the network infrastructure (could be as simple as a software firewall). You can use something like iptables to allow incoming connections from whitelisted IP addresses only.
If you want to do it through software, the server and client can use symmetric encryption. Only clients that know the key will be able to send meaningful messages. All other messages can be safely discarded.

C# and modbus/tcp

I need to read some data from a rs485 device. It is connected to a Aport-211W and this one is connected to my local network. This device opens a server on port 502 and this is the rs485 port of the device I wanted to read. The protocoll is modbus.
My first try was to link this mobus/tcp to a local COM Port on my computer with this Software and read everything through it. But I dont want to use an other software for this and now my question is: How can i directly connect from a C# program to the modbus/tcp server and read data out?
I have already found some libraries but none of them is able to connect to the device. I have closed the Serial Port Redirector because it blocks the communication. Has anybody done something like this before?
Aport-211W is just a gateway between your MODBUS device (probably MODBUS RTU) and network. It does not do any protocol conversion, which means that you have MODBUS RTU over TCP and not plain MODBUS TCP protocol. These are different protocols, and you need to adjust according to that.
Well, you can write on yourself if you want, that way u can contol the stuff ur self and will be bespoke.
mostly, it would be Modbus RTU over TCP from the Slave.
Just create sockets to communicate with the Aport as they communicate through TCP.

Forward UDP packets to several IPs maintaining the original source address

I have a working system that receives data via UDP packets sent to a fixed IP:Port and I want to use a program (some kind of proxy?) to send a copy of those packets to a new IP:Port (or a list of IP:Ports, but all inside the same LAN as the program).
Not as easy as it seems, because I need the copied packets to have the same Source IP address as the original ones.
In my research, I have found PCap.Net (WinPCap .NET wrapper) to be useful, because it can build a Packet from scratch and it supports modifying all the address fields. I have managed to capture the packets and build them. But somewhat they are not arriving at the desired destination (!?). Should I use a different PacketCommunicator to receive and send them?
Anyway, the question is not fully related to PCap.Net but to know alternative ways to achieve my desired goal. Via a free application? commercial application? Open source sample? Any other library to use?
My systems are Windows based (no Linux available here). And I have C# (.NET) experience (I can not use a C++ library, if NET bindings are not available).
Many thanks for your help
I know it's an old question, but this is the answer:
http://code.google.com/p/samplicator/
Listens for UDP and forwards it to one or more other IP addresses, optionally spoofing (the original) source IP address.
Used for forwarding netflow/sflow/syslog etc. packets.
you should think about network first. it may not be possible if traffic needs to go through router.
the original packet came through:
source->router->your server
if you are trying to sent it back out like so:
your server->router->another computer
then the router may not even accept this traffic, since it can not originate from your computer, according to routers configuration. just think about it - i could send traffic as anybody, if that was allowed.
however, in LAN that's very doable (unless you have some sort of MAC spoofing protection on your switches)
What you are trying to do is called "UDP Forwarding". You receive a UDP packet and then forward it to another host
Here is an application that does that (seems to be free)
in addition to keeping the source ip address and changing the destination ip address
you MUST swap the source and destination mac addresses.
if you send a raw packet out to your router/switch/modem, but the mac address is not addresses to it.
it will be dropped.
basicly, you have to revise every network layer your dealing with, and handle addressing approperately.
Sorry for my spelling
If you try to spoof the destination address to do things like netflow relaying you often will get blocked by anti-spoofing routers inbetween. I encountered this with AWS for example.
The solution is to take the RAW udp packet and then just send that along to your new destination inside another udp packet. When it reaches the destination you have to "unwrap" the packet and then send it to itself on the loopback interface (essentially "unwrapping").
You can do this with python code with the sockets module.

How does one capture H.323 voice traffic on a VOIP network?

What I am trying to do is capture the WAV data of a phone conversation on a VOIP network using SharpPCap/PCap.Net.
We are using the H.323 recommendation and my understanding is that voice data is located in the RTP packets. However, there is no way to heuristically determine if a UDP packet is a RTP packet, so we have to do more work before we can capture the data.
The H.323 recommendation apparently uses a lot of traffic on specific TCP ports to negotiate the call before the WAV data is sent via RTP. However, I am having very little luck determining what data is actually sent on those TCP ports, when it is sent, what the packets look like, how to handle it, etc.
If anyone has any information on how to go about this I'd really appreciate it. My Google-Fu seems to be failing me on this one.
Wireshark is your friend... I imagine it still has a plugin that will allow you to select a VoIP stream and then save to file. The fun part will be if you are using a switched network.
Wireshark + VoIP
you have to parse h.323 OLC message from both sides then you will be able to know what pakets to capture

How can two C# apps send messages over a WiFi Network?

Lets say I have my C# app installed on 2 laptops connected to a WiFi Wireless Local Area Network.
How can these apps send messages to each other? What method or library can I use? I heard of using sockets but I have no idea how to work with these.
You could use WCF to build a communication pipe between the 2 applications. WCF encapsulates the sockets into a more manageable interface. You can start here.
Basically, you'll want to do it the same way you would in any other language. You'll open a network connection of one flavor or another (raw TCP or UDP, or a higher level protocol like HTTP) with one side acting as a server and the other acting as a client. Then each side can write data through or read data sent by the other side. It's can get pretty complicated from there. If you Google "C# Sockets" or "C# HTTP", etc, you'll find quite a few tutorials on the subject.
This is a very good article on sending C# objects (which could include whatever messages that you want to send) over a Socket connection using the Binary Formatter. Although it is not the most efficient, it is quite easy to grasp and get working.

Categories