我希望 Pcap.net 有一些问题来更改 IP 地址
我找到了这段代码
我在 C# 中尝试这段代码:
private Packet ChangePacketIp(Packet packet, string oldIpAddress, string newIpAddress)
{
try
{
EthernetLayer ethernet = (EthernetLayer)packet.Ethernet.ExtractLayer();
IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.IpV4.ExtractLayer();
DateTime packetTimestamp = packet.Timestamp;
if (packet.Ethernet.IpV4.Source.ToString() == oldIpAddress)
{
ipV4Layer.Source = new IpV4Address(newIpAddress);
ipV4Layer.HeaderChecksum = null;
}
else if (packet.Ethernet.IpV4.Destination.ToString() == oldIpAddress)
{
ipV4Layer.CurrentDestination = new IpV4Address(newIpAddress);
ipV4Layer.HeaderChecksum = null;
}
if (packet.Ethernet.IpV4.Protocol == IpV4Protocol.Tcp)
{
TcpLayer tcpLayer = (TcpLayer)packet.Ethernet.IpV4.Tcp.ExtractLayer();
tcpLayer.Checksum = null;
ILayer payload = packet.Ethernet.IpV4.Tcp.Payload.ExtractLayer();
return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, tcpLayer, payload);
}
else if (packet.Ethernet.IpV4.Protocol == IpV4Protocol.Udp)
{
UdpLayer udpLayer = (UdpLayer)packet.Ethernet.IpV4.Udp.ExtractLayer();
udpLayer.Checksum = null;
ILayer payload = packet.Ethernet.IpV4.Udp.Payload.ExtractLayer();
return PacketBuilder.Build(packetTimestamp, ethernet, ipV4Layer, udpLayer, payload);
}
else
{
return null;
}
}
catch
{
return null;
}
如果我想在按钮事件中使用它,我试试这个:
ChangePacketIp( xxxxx ,"example","example");
但是我应该用 xxxxx 替换什么???
它想要数据包,但我现在不关心它
请帮忙