Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ip filter fix #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions itchatmp/controllers/mpapi/base/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import functools, logging, time, threading, traceback
import functools, logging, time, threading, traceback, ipaddress
from datetime import datetime, timedelta

from requests import get
Expand Down Expand Up @@ -210,8 +210,6 @@ def _wrap_result(result):
result = ReturnValue(result.json())
if 'ip_list' in result:
result['errcode'] = 0
for i, v in enumerate(result['ip_list']):
result['ip_list'][i] = v[:v.rfind('/')]
return result
r._wrap_result = _wrap_result
return r
Expand All @@ -232,4 +230,8 @@ def clear_server_list():
if not self._serverList:
logger.debug('Server list is loading, so ignore verifying once.')
return True
return request.remote_ip in self._serverList
for CIDR in self._serverList:
if ipaddress.ip_address(request.remote_ip) in ipaddress.ip_network(CIDR):
return True
return False