Пересылка пакетов между двумя сетевыми интерфейсами с помощью sharpcap и packetdotnet
Hi!I have my computer, that connect to two networks (network1 and network2) using 2 network adapters. First Net adapter (on my comp) connetcted to network1 and second net adapter connected to network2. This two networks don't connected between directly. Only my comp connected to to each one. I need that packages from network1 can be forwarded to network2 using this two adapters on my comp. I need some bridge between network1 and network2. I didn't find in Sharppcap and PacketDotNet any examples that demonstrate packets forwarding beetween two networks. I need to realized this using sharppcap and PacketDotNet.Can anybody help me?Thanks!
Что я уже пробовал:
<pre> private void SecondNetworkDevice_OnPacketArrival(object sender, CaptureEventArgs e) { try { Packet packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data); if (packet == null) return; long lengthData = e.Packet.Data.Length; PhysicalAddress sourcePhysicalAddress = null; PhysicalAddress destinationPhysicalAddress = null; IPAddress sourceIP = null; IPAddress destIP = null; if (packet is EthernetPacket) { var eth = ((EthernetPacket)packet); sourcePhysicalAddress = eth.SourceHwAddress; destinationPhysicalAddress = eth.DestinationHwAddress; IpPacket ip = (IpPacket)packet.Extract(typeof(IpPacket)); if (ip == null) { sourceIP = ip.SourceAddress; destIP = ip.DestinationAddress; if (destIP != null) { lock (lockAllowedClients) { if (listAllowedClients.Where(x => x.Value.IPAdress.ToString() == destIP.ToString()).Count() > 0) { eth.SourceHwAddress = macFirstNetWorkkDevice; eth.DestinationHwAddress = listAllowedClients.Where(x => x.Value.IPAdress.ToString() == destIP.ToString()) .Single() .Value.MACAddress; firstNetWorkkDevice.SendPacket(packet); } } } } } } catch (Exception ex) { Utils.LogErrors(ex); } } private void FirstNetworkDevice_OnPacketArrival(object sender, CaptureEventArgs e) { try { var packet = PacketDotNet.Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data); if (packet == null) return; long lengthData = e.Packet.Data.Length; PhysicalAddress sourcePhysicalAddress = null; PhysicalAddress destinationPhysicalAddress = null; IPAddress sourceIP = null; IPAddress destIP = null; if (packet is PacketDotNet.EthernetPacket) { var eth = ((EthernetPacket)packet); sourcePhysicalAddress = eth.SourceHwAddress; destinationPhysicalAddress = eth.DestinationHwAddress; IpPacket ip = (PacketDotNet.IpPacket)packet.Extract(typeof(PacketDotNet.IpPacket)); if (ip != null) { sourceIP = ip.SourceAddress; destIP = ip.DestinationAddress; lock (lockAllowedClients) { if (listAllowedClients != null && listAllowedClients.Count > 0) { if ( listAllowedClients.Where( x => x.Value.MACAddress.ToString() == sourcePhysicalAddress.ToString()).Count() > 0) { eth.SourceHwAddress = macSecondNetWorkkDevice; secondNetworkkDevice.SendPacket(packet); } } } if (sourcePhysicalAddress != null && sourceIP != null && !sourceIP.ToString().Contains("::") && !sourceIP.ToString().Contains(":")) { lock (lockAllClients) { if (!listAllClients.ContainsKey(sourcePhysicalAddress) && !listAllowedClients.ContainsKey(sourcePhysicalAddress)) { NetWorkClient netWorkClient = new NetWorkClient(sourcePhysicalAddress, sourceIP, lengthData); listAllClients.Add(sourcePhysicalAddress, netWorkClient); } else if (listAllClients.ContainsKey(sourcePhysicalAddress)) { listAllClients[sourcePhysicalAddress].CountBytes += lengthData; } } lock (lockAllowedClients) { if (listAllowedClients.ContainsKey(sourcePhysicalAddress)) { listAllowedClients[sourcePhysicalAddress].CountBytes += lengthData; } } } } } } catch (Exception ex) { Utils.LogErrors(ex); } }