Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
8450970e
Commit
8450970e
authored
Mar 06, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Developer's Pack
parent
6793e9b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
12 deletions
+43
-12
Program.cs
...ersPack/src/SendingASinglePacketWithSendPacket/Program.cs
+43
-12
No files found.
PcapDotNet.DevelopersPack/src/SendingASinglePacketWithSendPacket/Program.cs
View file @
8450970e
...
...
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using
PcapDotNet.Core
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Icmp
;
using
PcapDotNet.Packets.IpV4
;
namespace
SendingASinglePacketWithSendPacket
{
...
...
@@ -44,11 +46,11 @@ namespace SendingASinglePacketWithSendPacket
// Take the selected adapter
PacketDevice
selectedDevice
=
allDevices
[
deviceIndex
-
1
];
// Open the output device
using
(
PacketCommunicator
communicator
=
selectedDevice
.
Open
(
100
,
// name of the device
using
(
PacketCommunicator
communicator
=
selectedDevice
.
Open
(
100
,
// name of the device
PacketDeviceOpenAttributes
.
Promiscuous
,
// promiscuous mode
1000
))
// read timeout
1000
))
// read timeout
{
// Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1
MacAddress
source
=
new
MacAddress
(
"1:1:1:1:1:1"
);
...
...
@@ -56,17 +58,46 @@ namespace SendingASinglePacketWithSendPacket
// set mac source to 2:2:2:2:2:2
MacAddress
destination
=
new
MacAddress
(
"2:2:2:2:2:2"
);
// Fill the rest of the packet (ethernet payload)
byte
[]
ethernetPayloadBuffer
=
new
byte
[
100
];
for
(
int
i
=
0
;
i
!=
ethernetPayloadBuffer
.
Length
;
++
i
)
ethernetPayloadBuffer
[
i
]
=
(
byte
)(
i
%
256
);
Datagram
ethernetPayload
=
new
Datagram
(
ethernetPayloadBuffer
);
// Create the packets layers
// Ethernet Layer
EthernetLayer
ethernetLayer
=
new
EthernetLayer
{
Source
=
source
,
Destination
=
destination
};
// IPv4 Layer
IpV4Layer
ipV4Layer
=
new
IpV4Layer
{
Source
=
new
IpV4Address
(
"1.2.3.4"
),
Ttl
=
128
,
// The rest of the important parameters will be set for each packet
};
//
Create the packet
Packet
packet
=
PacketBuilder
.
Ethernet
(
DateTime
.
Now
,
source
,
destination
,
EthernetType
.
IpV4
,
ethernetPayload
);
//
ICMP Layer
IcmpEchoLayer
icmpLayer
=
new
IcmpEchoLayer
(
);
// Send down the packet
communicator
.
SendPacket
(
packet
);
// Create the builder that will build our packets
PacketBuilder
builder
=
new
PacketBuilder
(
ethernetLayer
,
ipV4Layer
,
icmpLayer
);
// Send 100 Pings to different destination with different parameters
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
// Set IPv4 parameters
ipV4Layer
.
Destination
=
new
IpV4Address
(
"2.3.4."
+
i
);
ipV4Layer
.
Identification
=
(
ushort
)
i
;
// Set ICMP parameters
icmpLayer
.
SequenceNumber
=
(
ushort
)
i
;
icmpLayer
.
Identifier
=
(
ushort
)
i
;
// Build the packet
Packet
packet
=
builder
.
Build
(
DateTime
.
Now
);
// Send down the packet
communicator
.
SendPacket
(
packet
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment