3

I am playing around with a way to kick cheaters in Modern Warfare 2 (when you are the host). I have been able to use winpcap to sniff packages to identify the player names and their IPs.

I need a way to block all traffic (or just the target IPs UDP traffic to my machine). Hence the player will timeout/lagout.

Does anyone know of an available library that lets me do this easily. I could go about doing this the hard way and install Windows DDK and mess around in C++ to create a low level NDIS driver, but being überly rusty on C++ and all the typical compile issues that comes when compiling template code for this, I prefer some ready coded library for this.

Or maybe someone has a better idea that would work?

Solution: Use Windows Firewall. Easy API to create and remove rules on the fly. Any way to turn the "internet off" in windows using c#?

And a a test program that does this now works. I kicked 2 people out of the game.

Community
  • 1
  • 1
Wolf5
  • 16,600
  • 12
  • 59
  • 58
  • If the player is behind an Internet proxy, then you'll be blocking all traffic from anyone on the same proxy server. – John Saunders Feb 22 '10 at 10:02
  • True. But the odds for that being a problem here is minimal, as this game almost requires everyone to not be behind a proxy (to host). And if it was to happen, odds are that the cheater is playing together with a friend. And then they both should go. Oh. If one can also block by Port, you can single out 1 person behind a common IP. – Wolf5 Feb 22 '10 at 12:50

2 Answers2

1

Are you running a firewall? Maybe you could use the firewall's API to reject connection requests from the offending host. For example, the "Windows Firewall with Advanced Security" API is probably available on a lot of PCs.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • I was thinking on maybe distributing this among friends, so primarily I want something I can distribute (or that is easily reinstallable if I reinstall my OS). If I can't get anything else to work, what you say might be a way to go. But what firewalls come with a ready-to-use API? – Wolf5 Feb 22 '10 at 10:26
0

You should be able to put an invalid entry for that IP into the Windows Hosts file. Here's some C# code that might work for you.

This place discusses a way to use IPSec to filter IP addresses. It's very manual though. Here's the process:

Under Local Security Settings / IP Security Policies

  1. Create a new IP Filter list
  2. Source IP is My IP address
  3. Destination (in this example) is 129.74.250.101 (nd.edu)
  4. Protocol is any
  5. Create a new IP Security Policy (use Kerberos 5 authentication)
  6. Add an IP Security Rule (this rule is not a tunnel) (all network connections)
  7. Add the new IP filter list that you just created. (require security)
  8. Assign the new policy

If you could figure out how to do that in C#, you're a winner.

Scott Whitlock
  • 13,739
  • 7
  • 65
  • 114
  • The OP wants to block incoming requests. Will editing the hosts file do that? I thought it only affected outgoing traffic. – ChrisF Feb 22 '10 at 10:04
  • @ChrisF: Does it matter? If your computer can't send any info back, their connection will drop. Their computer won't be able to get any position or state info from the game, so they can't continue to cheat. – Scott Whitlock Feb 22 '10 at 10:05
  • @Scott - that's true, but you still might not want the overhead of the incoming requests. BTW I didn't down-vote, I was just trying to understand where you were coming from with your suggestion. – ChrisF Feb 22 '10 at 10:11
  • Not a bad idea though. Does Windows 7 still have the "hosts" file? How do you add an "invalid entry"? I though the hosts file was only a custom "DNS" mapper from a name to IP. I need to block the IP. – Wolf5 Feb 22 '10 at 10:24
  • @Wolf5: I'm trying to think... this is how a lot of ad blocking software works, but I guess what they're doing is mapping a domain name to a black hole IP or something like 127.0.0.1 or 0.0.0.0. That won't work, but there is a way with IPSec apparently. I'll update my answer. – Scott Whitlock Feb 23 '10 at 01:36
  • That might work if I find a way to do that from .Net. But when you open that box, maybe using Windows Firewall do do the same? With Windows Firewall one would be able to select a port as well, thus not blocking a proxy, but a person behind a proxy. – Wolf5 Feb 23 '10 at 09:45
  • And what do you know: "Controlling Windows Firewall using C# via COM Interop": http://www.shafqatahmed.com/2008/01/controlling-win.html – Wolf5 Feb 23 '10 at 19:32
  • Found code here and there for controlling the firewall and tested to work. Now to implement it into my program. http://stackoverflow.com/questions/1242566/any-way-to-turn-the-internet-off-in-windows-using-c – Wolf5 Feb 23 '10 at 21:56
  • @Wolf5: glad you found something. Good luck! – Scott Whitlock Feb 24 '10 at 11:55
  • Just a future note for everyone who finds this, editing the hosts file will not affect incoming connections, the hosts file is simply a "DNS lookup file" and will only affect windows looking up a domain name. – jduncanator Aug 29 '13 at 02:24