Commit graph

19 commits

Author SHA1 Message Date
clowwindy
ce805f0aea license under Apache License v2.0 2015-02-03 14:10:36 +08:00
clowwindy
453a9c61a6 show CIDR error more friendly 2015-02-01 09:09:35 +08:00
Sunny
a0aa9173a8 Fix for Python3 map changed behavior
In Python3, map returns an iterator instead of list in Python2,
which cause map "lazier" than before, wrap with list() force it running.
2015-02-01 02:37:30 +08:00
Sunny
79b9b53dbe Never process empty string and prevent infinite loop
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.
2015-02-01 01:57:17 +08:00
Sunny
b11d848986 Fix for Python3 lambda behavior change
In Python3, lambda no longer support use tuple as syntax.
So, ugly changes is inevitable.
2015-02-01 01:34:18 +08:00
Sunny
aa28796524 Make common fit PEP8 2015-02-01 01:34:13 +08:00
Sunny
100ebcf064 Add IPNetwork class to support CIDR calculation
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.
2015-01-31 22:56:16 +08:00
Sunny
8783e0e9ae Move is_ip from asyncdns to common
Since implement CIDR forbidden need this function,
move it to common file seems to be a better choice.
2015-01-31 22:56:09 +08:00
clowwindy
70dae91e7c add tests for common.py 2014-11-06 14:04:28 +08:00
clowwindy
b5010df575 fix args on Python 3 2014-11-06 13:08:40 +08:00
clowwindy
efd45ddfc6 fix UDP server 2014-10-31 21:59:22 +08:00
clowwindy
0fd2f30911 lint code 2014-10-31 18:43:15 +08:00
clowwindy
2a53b67c65 python 3 support; not stable yet 2014-10-31 18:28:22 +08:00
clowwindy
972bf22e6d fix PEP8 2014-08-27 00:17:26 +08:00
clowwindy
a323f878e1 prefer addrtype 1 and 4 over 3 in UDP relay 2014-07-12 10:32:51 +08:00
clowwindy
45f9998fa9 more work 2014-06-08 14:17:26 +08:00
clowwindy
bacf9cb443 more work 2014-06-01 13:42:48 +08:00
clowwindy
c2f6bc369c more work 2014-06-01 11:01:11 +08:00
clowwindy
0d6c39900b more work 2014-05-30 23:55:33 +08:00