Previously we used logging.error(e) and traceback.print_exc()
to output error stack trace. The problem is, we want to
output the stack trace only when verbose > 0. The if statement
scattered around the code. So we replaced them with the new
utils.print_exception() call.
If user provide an empty string as network range, inet_pton will
treate it as an IPv6 unspecified address, it seems a bug but I
can't confirm. Then empty string will be converted to 0, 0 & 1
always be zero, so it caused dead loop.
Since forbidden ip is server-side only, disable it for local-side.
This commit also supress warning about IPv6 loopback because I can
confirm ::1/128 is the only loopback address, not like IPv4.
This commit also make "forbidden_ip" field available in config file.
If no forbidden ip specified in command line and config file,
default to "127.0.0.0/8,::1".
Usage:
Use IPNetwork(str|list<str>) to create an IPNetwork object.
Use operator 'in' to determine whether the specified
IP address is in the IP network or not, like:
>>> '192.168.1.1' in IPNetwork('192.168.1.0/24')
True
Both IPv4 and IPv6 address are supported.
Note: When using string to initialize the IPNetwork,
a comma seperated IP network list should be provided.
Currently, IPNetwork just support standard CIDR like:
x.x.x.x/y eg. 192.168.1.0/24
::x/y eg. ::1/10
If pure IP address was provided,
it will be treated as implicit IP network,
like 192.168.0.0 will be treated as 192.168.0.0/16
and 192.168.1.1 will be treated as 192.168.1.1/32
This implicit translate may cause some unexpected behavior,
like user provide 192.168.2.0 and expect it will be treated as
192.168.2.0/24 but actually it will be translated to
192.168.2.0/23 because there are 9 continuous 0 from right.
In order to avoid confusion, a warning message
will be displayed when pure IP address was provided.
Other variants of CIDR are not supported yet.