Ciao, da qualche giorno mi sto interessando a pasticciare con l'invio di pacchetti, ho scaricato Wireshark e mi diverto a controllare ciò che passa dalla mia scheda di rete.
Ora, ho scaricato le librerie di SharpPcap e PacketDotNet ed ho tentato di effettuare l'invio di un centinaio di pachetti di prova al mio sito. Ma quando lancio l'invio, vengono generati numerosi pacchetti ARP verso il router e all'esterno non esce nulla. Non capisco se sto sbagliando qualcosa relativamente al codice o se il problema riguarda la configurazione del router, NAT ecc...
Posto la parte di codice relativa all'invio dei pacchetti.
codice:
interfacciaSelezionata.Open();
for (int i = 0; i < 100; i++)
{
// Creo il pacchetto da inviare
ushort tcpSourcePort = 123;
ushort tcpDestinationPort = 80;
var tcpPacket = new TcpPacket(tcpSourcePort, tcpDestinationPort);
var ipSourceAddress = System.Net.IPAddress.Parse("textBox1.Text");
var ipDestinationAddress = System.Net.IPAddress.Parse(textBox2.Text);
var ipPacket = new IPv4Packet(ipSourceAddress, ipDestinationAddress);
var sourceHwAddress = "90-90-90-90-90-90";
var ethernetSourceHwAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(sourceHwAddress);
var destinationHwAddress = "80-80-80-80-80-80";
var ethernetDestinationHwAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(destinationHwAddress);
var ethernetPacket = new EthernetPacket(ethernetSourceHwAddress, ethernetDestinationHwAddress, EthernetPacketType.None);
ipPacket.PayloadPacket = tcpPacket;
ethernetPacket.PayloadPacket = ipPacket;
byte[] packetBytes = ethernetPacket.Bytes;
// Invio il pacchetto
interfacciaSelezionata.SendPacket(packetBytes);
}
interfacciaSelezionata.Close();
Grazie dell'aiuto.