思路:防止重复制造轮子,导入成熟的IP相关模块—IPy
import IPy
>>>'192.168.1.100' in IPy.IP('192.168.1.0/24')
is True
>>>'192.168.1.0/24' in IPy.IP('192.168.0.0/16')
is True
>>>'192.168.1.0/24' in IPy.IP('192.168.0.0-192.168.0.255')
is True
参考:https://www.cnblogs.com/cherishry/p/5916935.html