Last active
January 12, 2023 22:19
-
-
Save JonCanning/37b8405d52d258337f00ee511a7bb85b to your computer and use it in GitHub Desktop.
Send a packet using SharpPcap and PacketDotNet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: PacketDotNet" | |
#r "nuget: SharpPcap" | |
open PacketDotNet | |
open SharpPcap | |
open System.Net.NetworkInformation | |
open System.Net | |
open System.IO | |
let deviceName = "eth0" | |
let device = CaptureDeviceList.Instance |> Seq.find (fun d -> d.Name = deviceName) | |
device.Open() | |
let udp = UdpPacket(0us, 1812us, PayloadData = [| 0uy |]) | |
let ip = | |
IPv4Packet(IPAddress.Any, IPAddress.Parse "51.136.117.171", PayloadPacket = udp) | |
let eth = | |
EthernetPacket(device.MacAddress, PhysicalAddress.Parse "FF-FF-FF-FF-FF-FF", EthernetType.IPv4, PayloadPacket = ip) | |
ip.UpdateIPChecksum() | |
device.SendPacket eth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will not send to loopback
lo
"FF-FF-FF-FF-FF-FF"
is the magic that made this work, so don't change it