Any way to make this faster?
#1

So this is my Range Banning code:
Код:
stock BanRange(l1)
{
    printf("[BanRange] Banning Range Starting from: %d", l1);
	new docmd[128], ipttl[128];
	for(new i=1;i<256;i++)
	{
		for(new b=0;b<256;b++)
		{
		    for(new c=0;c<256;c++)
		    {
			    format(ipttl, sizeof(ipttl), "%d.%d.%d.%d", l1, i, b, c);
			    format(docmd, 128, "banip %s", ipttl);
			    SendRconCommand(docmd);
			}
		}
	}
	return 1;
}
Its slow and it would take hours to ban one range..
Anyway to make it more faster? or optimize it?
Reply
#2

cant u do 123.*.*.* and it bans all?
Reply
#3

This would ban all ips lol, you're looping through 256 ip part inside a 256 loop both inside 256 loop which loops through: 16777216 ip part. impossible to do this, and your code isn't a range ban code, it bans each n every ip.
Reply
#4

Provided you're using sscanf and zcmd, you could always use this:

Код:
CMD:banip(playerid, params[])
{
	new given_ip[16];
	if(sscanf(params, "s[16]", given_ip))
	{
	     // Invalid input...
	    return false;
	}

        new str[25];
	str = "banip ";
	strcat(str, given_ip);
	SendRconCommand(str);
	return true;
}
Reply
#5

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
This would ban all ips lol, you're looping through 256 ip part inside a 256 loop both inside 256 loop which loops through: 16777216 ip part. impossible to do this, and your code isn't a range ban code, it bans each n every ip.
It dosent ban each and every IP..
It will ban all the IPs under the first line e.g. 192

and cawfee

You cant directly set a string, You have to format it.
So that would return errors

+ The hell? ip isn't even declared on that command so it would basically send this: "banip " with no parameters.
Reply
#6

You can't ban IPs like that, can you explain me your code?
All I can see this loops banning 11.*.*.*
{11.1.1.1, 11.1.1.2, 11.1.1.3, etc etc etc, 11.255.255.255}
and you're looping through 16777216 ip part.
Reply
#7

Quote:
Originally Posted by MafiaOink
Посмотреть сообщение
It dosent ban each and every IP..
It will ban all the IPs under the first line e.g. 192

and cawfee

You cant directly set a string, You have to format it.
So that would return errors

+ The hell? ip isn't even declared on that command so it would basically send this: "banip " with no parameters.
My bad. Try it now. And by the way, format is not required in this case. Eliminating the need for format actually makes it slightly faster too.
Reply
#8

If you can't make your own range ban system, use RCON.
Quote:

/rcon banip [ip/iprange]

Use: /rcon banip 11.*.*.*, and none of this range will be able to access server.
Reply
#9

An entire class A range should never be range banned as that is way too broad. A class A range is in most cases shared by several different countries.

The 192 class A range (192.0.0.0 through 192.255.255.255) is in fact shared - and I'm not making this up - by no less than 104 different countries. Here's the top 5:

CountryNumer of IP addresses
United States11247369
Canada924255
Finland488406
Japan392666
Sweden337251
Reply
#10

Loled
pawn Код:
stock BanRange(l1)
{
    new str[16];
    printf("[BanRange] Banning Range Starting from: %d", l1);
    format(str, sizeof(str), "banip %d.*.*.*", l1);
    SendRconCommand(str);
    return 1;
}
? xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)