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

Linq to SQL C# Get Products in all child/sub child Categories too slow
C++ DLL does not unload with AppDomain
Sharing DB Access Methods between Client and Server in Entity Framework (C#.Net)
Can a Delphi 4 and/or Delphi 5 executable be integrated into a C# application?
WCF/REST Get image into picturebox?
Sonar-runner Exception with .NET Project
C# List<object> to IList cast bug in Unity3d
Logging lambda expressions
Deserializing response
How to find out size occupied by data table/data set in asp.net C#?
Change DB connection string after publishing a C# console app
excanvas js is not working in IE8 [duplicate]
count number of identical elements in two arrays in linq
WCF logging, set max file size?
LINQ concatenating elements in two string arrays [duplicate]
Trouble with PrintForm Control in C#

Categories

HOME
logging
netty
popover
blob
x86-64
sdk
terminal
ms-access-2010
psexec
genexus
osrm
hdf5
filehelpers
openam
google-street-view
autologin
datasource
uipath
ecmascript-2017
poisson
waterfall
tftp
meteor-accounts
restangular
r-factor
undo
foxpro
jql
bootcamp
motherboard
realloc
dotnetnuke-module
jquery-inputmask
ng-lightning
electron-packager
autodesk-data-management
uitextview
rexx
f#-fake
logan-square
niagara-ax
synchronized
anonymous-function
jenkins-docker
r-commander
nsalert
multi-select
chain
google-scholar
huawei
visual-web-developer
jspx
virtualenvwrapper
foreground
konakart
geokit
init
shtml
jmap
wizard
jersey-test-framework
matlab-engine
angular-promise
commercetools
php-gd
jain-sip
dnvm
cyberduck
roslyn-code-analysis
azure-mobile-app
clearquest
autopep8
fiware-health
drools-guvnor
sat4j
azure-worker-roles
step
lettuce
acrofields
autofilter
nop
thucydides
jfilechooser
google-mirror-api
ie-developer-tools
angularjs-select2
pyxplot
google-checkout
junction-table
servicemanager
ncml
shapado
states
flatten
wxperl
cherokee
parallel-python
xpolog
funambol
jexcelapi
method-call
javah
xslt-grouping
versions
dynamic-scope
html-help-workshop
bootstrap-protocol

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