@@ -46,50 +46,50 @@ public static void BlockAndRedirect()
46
46
MainDevice . Filter = "ip" ;
47
47
48
48
BRTask = Task . Run ( ( ) =>
49
- {
50
- RawCapture rawCapture ;
51
- EthernetPacket packet ;
52
-
53
- while ( BRMainSwitch )
54
- {
55
- if ( ( rawCapture = MainDevice . GetNextPacket ( ) ) != null )
56
- {
57
- packet = Packet . ParsePacket ( rawCapture . LinkLayerType , rawCapture . Data ) as EthernetPacket ;
58
- if ( packet == null )
59
- continue ;
60
-
61
- KeyValuePair < IPAddress , Device > device ;
62
-
63
- if ( ! ( device = Main . Devices . FirstOrDefault ( D => D . Value . MAC . Equals ( packet . SourceHardwareAddress ) ) ) . Equals ( default ( KeyValuePair < IPAddress , Device > ) ) && device . Value . Redirected )
64
- {
65
- if ( device . Value . UploadCap == 0 || device . Value . UploadCap > device . Value . PacketsSentSinceLastReset )
66
- {
67
- packet . SourceHardwareAddress = MainDevice . MacAddress ;
68
- packet . DestinationHardwareAddress = AppConfiguration . GatewayMac ;
69
- MainDevice . SendPacket ( packet ) ;
70
- device . Value . PacketsSentSinceLastReset += packet . Bytes . Length ;
71
- }
72
- }
73
- else if ( packet . SourceHardwareAddress . Equals ( AppConfiguration . GatewayMac ) )
74
- {
75
- IPv4Packet IPV4 = packet . Extract < IPv4Packet > ( ) ;
76
-
77
- if ( ! ( device = Main . Devices . FirstOrDefault ( D => D . Key . Equals ( IPV4 . DestinationAddress ) ) ) . Equals ( default ( KeyValuePair < IPAddress , Device > ) ) && device . Value . Redirected )
78
- {
79
- if ( device . Value . DownloadCap == 0 || device . Value . DownloadCap > device . Value . PacketsReceivedSinceLastReset )
80
- {
81
- packet . SourceHardwareAddress = MainDevice . MacAddress ;
82
- packet . DestinationHardwareAddress = device . Value . MAC ;
83
- MainDevice . SendPacket ( packet ) ;
84
- device . Value . PacketsReceivedSinceLastReset += packet . Bytes . Length ;
85
- }
86
- }
87
- }
88
- }
89
-
90
- SpoofClients ( ) ;
91
- }
92
- } ) ;
49
+ {
50
+ RawCapture rawCapture ;
51
+ EthernetPacket packet ;
52
+
53
+ while ( BRMainSwitch )
54
+ {
55
+ if ( ( rawCapture = MainDevice . GetNextPacket ( ) ) != null )
56
+ {
57
+ packet = Packet . ParsePacket ( rawCapture . LinkLayerType , rawCapture . Data ) as EthernetPacket ;
58
+ if ( packet == null )
59
+ continue ;
60
+
61
+ KeyValuePair < IPAddress , Device > device ;
62
+
63
+ if ( ! ( device = Main . Devices . FirstOrDefault ( D => D . Value . MAC . Equals ( packet . SourceHardwareAddress ) ) ) . Equals ( default ( KeyValuePair < IPAddress , Device > ) ) && device . Value . Redirected )
64
+ {
65
+ if ( device . Value . UploadCap == 0 || device . Value . UploadCap > device . Value . PacketsSentSinceLastReset )
66
+ {
67
+ packet . SourceHardwareAddress = MainDevice . MacAddress ;
68
+ packet . DestinationHardwareAddress = AppConfiguration . GatewayMac ;
69
+ MainDevice . SendPacket ( packet ) ;
70
+ device . Value . PacketsSentSinceLastReset += packet . Bytes . Length ;
71
+ }
72
+ }
73
+ else if ( packet . SourceHardwareAddress . Equals ( AppConfiguration . GatewayMac ) )
74
+ {
75
+ IPv4Packet IPV4 = packet . Extract < IPv4Packet > ( ) ;
76
+
77
+ if ( ! ( device = Main . Devices . FirstOrDefault ( D => D . Key . Equals ( IPV4 . DestinationAddress ) ) ) . Equals ( default ( KeyValuePair < IPAddress , Device > ) ) && device . Value . Redirected )
78
+ {
79
+ if ( device . Value . DownloadCap == 0 || device . Value . DownloadCap > device . Value . PacketsReceivedSinceLastReset )
80
+ {
81
+ packet . SourceHardwareAddress = MainDevice . MacAddress ;
82
+ packet . DestinationHardwareAddress = device . Value . MAC ;
83
+ MainDevice . SendPacket ( packet ) ;
84
+ device . Value . PacketsReceivedSinceLastReset += packet . Bytes . Length ;
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ SpoofClients ( ) ;
91
+ }
92
+ } ) ;
93
93
}
94
94
95
95
/// <summary>
@@ -135,12 +135,12 @@ public static void ConstructAndSendArp(Device device, BROperation Operation)
135
135
}
136
136
else
137
137
{
138
- ArpPacket ArpPacketForVicProtection = new ArpPacket ( ArpOperation . Request , MainDevice . MacAddress , AppConfiguration . LocalIp , device . MAC , device . IP ) ;
139
- ArpPacket ArpPacketForGatewayProtection = new ArpPacket ( ArpOperation . Request , MainDevice . MacAddress , AppConfiguration . LocalIp , AppConfiguration . GatewayMac , AppConfiguration . GatewayIp )
138
+ ArpPacket ArpPacketForVicProtection = new ArpPacket ( ArpOperation . Response , MainDevice . MacAddress , AppConfiguration . LocalIp , device . MAC , device . IP ) ;
139
+ ArpPacket ArpPacketForGatewayProtection = new ArpPacket ( ArpOperation . Response , MainDevice . MacAddress , AppConfiguration . LocalIp , AppConfiguration . GatewayMac , AppConfiguration . GatewayIp ) ;
140
+ EthernetPacket EtherPacketForVicProtection = new EthernetPacket ( device . MAC , MainDevice . MacAddress , EthernetType . Arp )
140
141
{
141
142
PayloadPacket = ArpPacketForVicProtection
142
143
} ;
143
- EthernetPacket EtherPacketForVicProtection = new EthernetPacket ( device . MAC , MainDevice . MacAddress , EthernetType . Arp ) ;
144
144
EthernetPacket EtherPacketForGatewayProtection = new EthernetPacket ( AppConfiguration . GatewayMac , MainDevice . MacAddress , EthernetType . Arp )
145
145
{
146
146
PayloadPacket = ArpPacketForGatewayProtection
0 commit comments