You can't anymore, as access to raw sockets has been restricted in the desktop versions of Windows:
On Windows 7, Windows Vista, Windows XP with Service Pack 2 (SP2), and Windows XP with Service Pack 3 (SP3), the ability to send traffic over raw sockets has been restricted in several ways:
- TCP data cannot be sent over raw sockets.
- UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
- A call to the
bind
function with a raw socket for the IPPROTO_TCP
protocol is not allowed.
Note The bind
function with a raw socket is allowed for other protocols (IPPROTO_IP
, IPPROTO_UDP
, or IPPROTO_SCTP
, for example).
(From Dev Center - Desktop - TCP/IP Raw Sockets)
You can create a raw socket fairly easily:
Socket s = new Socket(ip.AddressFamily, SocketType.Raw, ProtocolType.Ip);
At which point its on you to construct the appropriate datagram (which would be a separate question if you don't have the documentation on how to do this to hand)