tags:

views:

69

answers:

2

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

The next thing I need is 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 really 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. http://stackoverflow.com/questions/1242566/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 :))

A: 

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
The OP wants to block incoming requests. Will editing the hosts file do that? I thought it only affected outgoing traffic.
ChrisF
@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
@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
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
@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
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
And what do you know:"Controlling Windows Firewall using C# via COM Interop":http://www.shafqatahmed.com/2008/01/controlling-win.html
Wolf5
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
@Wolf5: glad you found something. Good luck!
Scott Whitlock
+1  A: 

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
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
Windows Firewall
Wolf5