Jump to content
  • Advertisement
Sign in to follow this  
Kobaltic

IP ranges

This topic is 4025 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I specify an IP range in c++? I want to be able to have 127.68.1-255.1-255, all the IPs in that range are affected. I would like it so I can type in either 127.68.xxx.xxx or just 127.68. and have all the range affected.

Share this post


Link to post
Share on other sites
Advertisement
Affected by what?

Do you mean broadcasting a packet to an entire subnet?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kobaltic
It is going to be a ban.


Ban from what?

C++ is language. It has no concept of networks and can't ban anyone.

Is this for an application, a server, a service, which platform, ...

Do you have administrative rights in the network you'll be performing this, is this incoming or outgoing traffic, per-application or network-wide?

Share this post


Link to post
Share on other sites
it is for a video game. we have a standard ban function. such as ban 128.69.165.21 but I need it to ban the entire range of 128.69 or whatever the IP is.

Share this post


Link to post
Share on other sites
The "ban" function is something you have implemented.
Go to wherever your code compares to a specific IP range, and change that comparison to compare a subnet based on a netmask.

For example, if you store and test your ban address as such:
  struct ban {
time_t expires;
char why[100];
unsigned int ipaddr;
};

std::vector<ban> g_bans;

bool is_banned(unsigned int ipaddr) {
for (size_t i = 0, n = g_bans.size(); i != n; ++i) {
if (ipaddr == g_bans.ipaddr) return true;
}
return false;
}


You should change the code to be as such:
  struct ban {
time_t expires;
char why[100];
unsigned int ipaddr;
unsigned int netmask;
};

std::vector<ban> g_bans;

bool is_banned(unsigned int ipaddr) {
for (size_t i = 0, n = g_bans.size(); i != n; ++i) {
unsigned int netmask = g_bans.netmask;
if ((ipaddr & netmask) == (g_bans.ipaddr & netmask)) return true;
}
return false;
}


When you add a ban, also add a netmask, which could be 255.255.0.0 for the ban you suggest at the top. Use 255.255.255.255 for the case that only a given IP address is banned. Make sure to call htonl() on the netmask when you do it for the ipaddr, so they are in sync!

Share this post


Link to post
Share on other sites
Wouldn't that just be a range on the subnet mask?


Well let me go into more detail. Our problem is that people get banned. They use a proxy server and come right back in under a new IP. We are trying to stop this. Would a ban range be the best solution or is there another. I wanted to ban mac addresses but not sure on how to obtain a mac addy. Any thoughts.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kobaltic
Wouldn't that just be a range on the subnet mask?


Well let me go into more detail. Our problem is that people get banned. They use a proxy server and come right back in under a new IP. We are trying to stop this. Would a ban range be the best solution or is there another. I wanted to ban mac addresses but not sure on how to obtain a mac addy. Any thoughts.


No, a subnet mask is an IP range. It just happens to be used for a specific purpose (routing).

You cannot ban by mac addresses unless on a LAN. All frames will share the MAC address of the router with a WAN interface otherwise. Even if you are on a LAN I'm not sure how one would query the MAC address of machines you are communicating with, but seeing as its easy to change your MAC address this isn't much protection anyway.

Just add the proxy to the ban list. Then when other players who have been banned try use the proxy they will be unable to connect.

What kind of protocol are you using that has lots of proxies available for it, HTTP or something?

Share this post


Link to post
Share on other sites
I am not sure how to find the proxy addy. I know very little about proxy servers. Here is what I see as the admin of the server.

Player X IP 24.216.32.16

So I type in : ban 24.216.32.16 boot 24.216.32.16

Then he is banned and booted.
10 seconds later I see

Player X IP 24.216.54.89

So I ban and boot. Then it repeats forever.

As the server owner I can go into a .cfg file and type in ban 24.216 then it bans the range. However I have to restart the server which boots everyone. We want to add the function to the console so a remote admin can control it. Also not all admins have access to the .cfg files.

I was under the impression that one could use any proxy server to hide their real Ip and keep getting masked ones through the proxy server.

I am not sure of the protocol. This is my first adventure into programming the network portion of the game. I see udp all over the place.

Share this post


Link to post
Share on other sites
- Which server is this?

- Do you have the source code to the server and the facilities to build it?

If not, the C++ comment in the OP is misleading. If this is a commercial game server, then there's documentation explaining how to ban people.

If this is some third-party server, then go to their support site.

If this is private project, then ask the creator, owner, maintainer or whover is in charge and has the abilitiy to do this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!