Запись лог файла - C#
Формулировка задачи:
Доброго времени суток, есть программа которая сниферит сетевую карту. события приходят в виде
Сейчас пишется все что валится на сетевушку, а как сделать что бы можно было писать при условии DestinationPort=25010
[EthernetPacket: SourceHwAddress=00:e0:81:c1:bd:f2, DestinationHwAddress=00:25:22:b9:89:2d, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=54243, DestinationPort=25010, Flags={syn[0x76538add,1985186525]}] [EthernetPacket: SourceHwAddress=00:e0:81:c1:bd:f2, DestinationHwAddress=ff:ff:ff:ff:ff:ff, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.255, HeaderLength=5, Protocol=UDP, TimeToLive=128][UDPPacket: SourcePort=137, DestinationPort=137] [EthernetPacket: SourceHwAddress=00:e0:81:c1:bd:f2, DestinationHwAddress=00:25:22:b9:89:2d, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=7770, DestinationPort=21393, Flags={ack[3981738959 (0xed5483cf)]}] [EthernetPacket: SourceHwAddress=00:e0:81:c1:bd:f2, DestinationHwAddress=00:25:22:b9:89:2d, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=7770, DestinationPort=21393, Flags={ack[3981738959 (0xed5483cf)]}] [EthernetPacket: SourceHwAddress=00:e0:81:c1:bd:f2, DestinationHwAddress=00:25:22:b9:89:2d, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=7770, DestinationPort=21393, Flags={ack[3981738959 (0xed5483cf)]|psh}] [EthernetPacket: SourceHwAddress=00:25:22:b9:89:2d, DestinationHwAddress=00:e0:81:c1:bd:f2, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.13, DestinationAddress=192.168.0.254, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=21393, DestinationPort=7770, Flags={ack[1545226613 (0x5c1a4975)]}] [EthernetPacket: SourceHwAddress=00:0c:42:8a:08:bc, DestinationHwAddress=00:25:22:b9:89:2d, Type=IpV4][IPv4Packet: SourceAddress=217.69.139.58, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=54][TCPPacket: SourcePort=443, DestinationPort=23839, Flags={ack[3296399675 (0xc47b113b)]|psh}] [EthernetPacket: SourceHwAddress=00:25:22:b9:89:2d, DestinationHwAddress=00:0c:42:8a:08:bc, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.13, DestinationAddress=217.69.139.58, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=23839, DestinationPort=443, Flags={ack[706690463 (0x2a1f3d9f)]}]
Такс с этим разобрался. Подскажите ка можно вытащит значение SourceAddress
Решение задачи: «Запись лог файла»
textual
Листинг программы
var regex = new Regex(@"SourceAddress=\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"); var match = regex.Match("[EthernetPacket: SourceHwAddress=00:e0: 81:c1: bd:f2, DestinationHwAddress = 00:25:22:b9: 89:2d, Type=IpV4][IPv4Packet: SourceAddress=192.168.0.254, DestinationAddress=192.168.0.13, HeaderLength=5, Protocol=TCP, TimeToLive=128][TCPPacket: SourcePort=54243, DestinationPort=25010, Flags ={ syn[0x76538add, 1985186525]}]"); if (match.Success) { var sourceAddress = match.Value.Remove(0,14); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д