TCP 또는 HTTP 패킷을 보내지 만 작동하지 않는 Pcap.Net 0.10.0 (67076)을 사용하고 UDP 패킷에서만 작동합니까 ?? TCPViewer에 표시되는 UDP 패킷을 볼 수 있지만 TCP 또는 HTTP 패킷으로 표시됩니다.C# Pcap.Net 보내기 TCP, HTTP 패킷이 작동하지 않습니다.
나는 윈도우 7 64 비트를 사용하지만, 실제로 애플리케이션 x86 플랫폼을 빌드한다.
여기 내 코드입니다.
using System;
using System.Collections.Generic;
using System.Linq;
using PcapDotNet.Base;
using PcapDotNet.Core;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Dns;
using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.Gre;
using PcapDotNet.Packets.Http;
using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.Igmp;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.Transport;
using System.Text;
namespace PcapTest
{
class Program
{
static void Main(string[] args)
{
// Retrieve the device list from the local machine
IList<LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine;
if (allDevices.Count == 0)
{
Console.WriteLine("No interfaces found! Make sure WinPcap is installed.");
return;
}
// Print the list
for (int i = 0; i != allDevices.Count; ++i)
{
LivePacketDevice device = allDevices[i];
Console.Write(String.Format("{0}. {1}", (i + 1), device.Name));
Console.WriteLine(device.Description != null ? String.Format(" ({0})", device.Description) : " (No description available)");
}
int deviceIndex = 0;
do
{
Console.WriteLine(String.Format("Enter the interface number (1-{0}):", allDevices.Count));
string deviceIndexString = Console.ReadLine();
if (!int.TryParse(deviceIndexString, out deviceIndex) ||
deviceIndex < 1 || deviceIndex > allDevices.Count)
{
deviceIndex = 0;
}
} while (deviceIndex == 0);
// Take the selected adapter
PacketDevice selectedDevice = allDevices[deviceIndex - 1];
// Open the output device
using (PacketCommunicator communicator = selectedDevice.Open(69559, PacketDeviceOpenAttributes.Promiscuous, 1000)) // read timeout
{
communicator.SendPacket(BuildHttpPacket());
}
Console.ReadKey();
}
private static Packet BuildHttpPacket()
{
EthernetLayer ethernetLayer =
new EthernetLayer
{
Source = new MacAddress("01:01:01:01:01:01"),
Destination = new MacAddress("02:02:02:02:02:02"),
EtherType = EthernetType.None, // Will be filled automatically.
};
IpV4Layer ipV4Layer =
new IpV4Layer
{
Source = new IpV4Address("99.99.99.99"),
CurrentDestination = new IpV4Address("111.90.147.168"),
Fragmentation = IpV4Fragmentation.None,
HeaderChecksum = null, // Will be filled automatically.
Identification = 123,
Options = IpV4Options.None,
Protocol = null, // Will be filled automatically.
Ttl = 100,
TypeOfService = 0,
};
TcpLayer tcpLayer =
new TcpLayer
{
SourcePort = 4050,
DestinationPort = 80,
Checksum = null, // Will be filled automatically.
SequenceNumber = 100,
AcknowledgmentNumber = 50,
ControlBits = TcpControlBits.Acknowledgment,
Window = 100,
UrgentPointer = 0,
Options = TcpOptions.None,
};
HttpRequestLayer httpLayer =
new HttpRequestLayer
{
Version = HttpVersion.Version11,
Header = new HttpHeader(new HttpContentLengthField(11)),
Body = new Datagram(Encoding.ASCII.GetBytes("hello world")),
Method = new HttpRequestMethod(HttpRequestKnownMethod.Get),
Uri = @"http://pcapdot.net/",
};
PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, tcpLayer, httpLayer);
return builder.Build(DateTime.Now);
}
}
}
http://en.wikipedia.org/wiki/Transmission_Control_Protocol에서 자세한 내용을 참조하십시오? Pcap.Net은 현재 단일 패킷을 만드는 데만 사용할 수 있으므로 TCP 스트림을 만들려면 모든 TCP 3 방향 핸드 셰이크를 처리하고 다음 패킷의 시퀀스 및 승인 번호를 수정해야합니다. – brickner
@brickner 답장을 보내 주셔서 감사합니다. 내 IP 주소 (True IP)를 사용하고 pcapdotnet을 사용하여 포트 80에서 내 VPS 서버에 TCP 패킷 요청을 작성합니다! wireshark에 대한 요청을 볼 수는 있지만 서버에이 요청이 표시되지 않습니다. – vietnguyen09