c#


TCP packet creation [closed]


can anybody tell me how to create a TCP packet using C# ????
Looks like you are looking for the TCP Client class.
Look at MSDN and read through the System.Net.Sockets namespace documentation for more information.
You don't create TCP packets. TCP presents a stream-based abstraction; you read and write streams of bytes to/from the network socket. The fact that the network very probably treats these as packets at some point is not something you need to care about at the application level.
If you do need to care, you can use a tool such as GNU netcat to send traffic.
May I advise you to this library: http://www.eex-dev.net/fileadmin/user_upload/apidoc/NetworkLibrary/index.html?
Here is the code for sending a custom TCP packet:
//Create a list for the interfaces
List<EthernetInterface> wpcInterfaces = new List<EthernetInterface>();
//Get all local interfaces
WinPcapInterface[] arWpc = EthernetInterface.GetAllPcapInterfaces();
//Create a router
Router rRouter = new Router();
//Foreach WinPcapInterface of this host
foreach (WinPcapInterface wpc in arWpc)
{
//Create a new interface handler and start it
EthernetInterface ipInterface = new EthernetInterface(wpc);
ipInterface.Start();
//Then add it to the router and to our list
wpcInterfaces.Add(ipInterface);
rRouter.AddInterface(ipInterface);
}
//Create a TCP frame
TCPFrame tcpFrame = new TCPFrame();
tcpFrame.DestinationPort = 80;
tcpFrame.SourcePort = 12345;
tcpFrame.AcknowledgementFlagSet = true;
//Create an IP frame and put the TCP frame into it
IPv4Frame ipFrame = new IPv4Frame();
ipFrame.DestinationAddress = IPAddress.Parse("192.168.0.1");
ipFrame.SourceAddress = IPAddress.Parse("192.168.1.254");
ipFrame.EncapsulatedFrame = tcpFrame;
//Send the frame
rRouter.PushTraffic(tcpFrame);
//Cleanup resources
rRouter.Cleanup();
//Start the cleanup process for all interfaces
foreach (EthernetInterface ipInterface in wpcInterfaces)
{
ipInterface.Cleanup();
}
//Stop all handlers
rRouter.Stop();
//Stop all interfaces
foreach (EthernetInterface ipInterface in wpcInterfaces)
{
ipInterface.Stop();
}
Hopefully it helps. :)
Have a look at the System.Net.Sockets namespace. In particular, at the System.Net.Sockets.Socket class.

Related Links

evaluate dynamically created formula on large (in memory) flat table
Referencing a list but not all the members are being copied
how to use interface as object class
C# Code doesn’t compile verifying files before process start
VS-2012 : Breakpoint will not currently be hit. No symbols have been loaded for this document
C# read XML File and select Nodes
Serial port and multithreading issue
Where to place application settings for a WPF application
Prism DelgateComand throws an exception
XML class Error : Object reference not set to an instance of an object [duplicate]
RegEx - Version in filename
C# dictionary key split to JSON key value?
Injecting C++ DLLs into notepad on windows 10 using C#
DLL Could not be found in the project folder
C# Append text with Encoding.UTF8
abstract class with more then one parameterized constructor and derived class with parameterized constructor

Categories

HOME
spring-boot
ckan
model-view-controller
system-calls
virtual-machine
ssh
mifare
itext7
confluence-rest-api
segmentation-fault
aspectj
distinct
adroitlogic
saucelabs
popup
box2d
web-testing
google-closure-compiler
owncloud
smooth-scrolling
ofbiz
loader
dev-c++
procedural-generation
handle
jopendocument
stack-trace
angular-schema-form
spring-data-gemfire
login-required
slim-lang
gitosis
asp.net-webhooks
ragel
javafxports
sdl-2
outlook-2010
ngrok
julia-jump
ssdp
ape-phylo
libzip
f#-fake
html-entities
spring-data-commons
yank
nao-robot
ng-class
serialversionuid
ear
dna-sequence
cc
qt3d
mongodb-3.3
indoor-positioning-system
universe
recurring
window.location
cexception
salesforce-service-cloud
calc
jquery-draggable
opendolphin
android-togglebutton
roslyn-code-analysis
xml-simple
cakephp-2.6
gcc-warning
chunks
backtrace
optimistic-locking
grunt-contrib-connect
famous-engine
nsnotificationcenter
cs193p
power-management
slimscroll
kernel-density
carrier
google-voice
ia-32
kohana-orm
dynamic-expresso
msbuild-task
reference-manual
microsoft-speech-platform
configurationsection
correctness
motordriver
custom-cursor
android-memory
sqlbuddy
nsundomanager
ruby-1.9
jqzoom
discussion-board
object-tag
excellibrary
web-search
datadude
atmega16

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App