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

Combobox Column biding in WPF with MVVM pattern (Galasoft)
writing array values to file C#
How do I send data to the pre-generated Asp.net database?
Binding combobox - WPF & C#
Suppress exception while querying documentDB
WPF treeview context menu
add ComboBox dynamically with Locations in UWP
In the result of the analysis of the SONARQUBE server does not show correctly the Total of lines of code and nor the errors of code
How do I refer to a control in a WPF nested ListView?
Not able to read an XML file in a directory?
ASPX Session State null exception on Postback
Selenium and Aurelia, how make test wait for the page to load and HTTP calls to complete
OpenQA.Selenium.ElementNotVisibleException' in WebDriver.dll while trying to click on the link
Add items to Listbox
How do use LParam in Pinvoke GlobalGetAtomName
Getting the Arizona Standard Time in .net

Categories

HOME
ckan
typo3
network-programming
gap-system
conceptual
arcgis
mifare
angularjs-directive
jshell
osx-yosemite
ndepend
mongodb-replica-set
oxid
dat.gui
facebook-marketing-api
powerpivot
airbnb
orange
project-reactor
novacode-docx
beacon
hl7-fhir
bug-reporting
vala
multipart
rndis
tcpdf
ckeditor4.x
traveling-salesman
cloudformation
libxml2
setup-project
checkmarx
windows-10-mobile
delphi-2010
deferred
availability
angularjs-resource
mootools
tunnel
wunderground
asp.net-webhooks
perf
azure-storage-files
client-server
observer-pattern
ng-lightning
idea-plugin
socketcluster
file-descriptor
glide-image-library
bootstrap-carousel
html-entities
automapper-4
easyquery
grib
trusted-computing
suitesparse
lattice
blackberry-webworks
hfp
audiorecord
skbio
wordpress-plugin
ewam
gnu-sort
log-analysis
stderr
parseexception
grunt-contrib-connect
mind-manager
go-gin
msdropdown
farpoint-spread
grunt-contrib-imagemin
azure-scheduler
http-compression
nx
gpl
idoc
report-viewer2010
filedialog
django-admin-tools
optimistic-concurrency
facebook-winjs-sdk
pinchzoom
rjs
overlays
lightopenid
glassfish-embedded
datadude
hotfix

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