From ed038231829f97d01fea509f0d100634048d4179 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Thu, 11 May 2017 18:07:38 +0300 Subject: [PATCH 1/9] ASN check --- blockcheck.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/blockcheck.py b/blockcheck.py index fbdadc1..f657459 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -12,6 +12,7 @@ import os.path import dns.resolver import dns.exception import ipaddress +from ipwhois import IPWhois ''' @@ -802,6 +803,11 @@ def check_ipv6_availability(): print(": IPv6 недоступен.") return False +def get_nicinfo(ipaddr): + rdap_response = IPWhois(ipaddr) + nicinfo = rdap_response.lookup_rdap(depth=1) + return nicinfo + def main(): ipv6_addr = None global ipv6_available @@ -822,6 +828,11 @@ def main(): if ip_isp: if ipv6_available: print("IP: {}, IPv6: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), _mask_ip(ipv6_addr), ip_isp[1])) + asn4 = get_nicinfo(ip_isp[0]) + asn6 = get_nicinfo(ipv6_addr) + if asn4 != asn6: + ipv6_available = False + print ("Вероятно у вас IPv6 туннель, отключаем проверку IPv6") else: print("IP: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), ip_isp[1])) print() From afe2e732a99b4312574bd32bc7df187300a683ec Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Thu, 11 May 2017 18:15:11 +0300 Subject: [PATCH 2/9] update requirements --- blockcheck.py | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/blockcheck.py b/blockcheck.py index f657459..b409df3 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -832,7 +832,7 @@ def main(): asn6 = get_nicinfo(ipv6_addr) if asn4 != asn6: ipv6_available = False - print ("Вероятно у вас IPv6 туннель, отключаем проверку IPv6") + print("Вероятно у вас IPv6 туннель, отключаем проверку IPv6") else: print("IP: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), ip_isp[1])) print() diff --git a/requirements.txt b/requirements.txt index 2f73596..655871c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ dnspython +ipwhois From 699ea52c6ddf6d99d69f4dd00920afce39ea34d6 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Fri, 12 May 2017 12:11:42 +0300 Subject: [PATCH 3/9] check force_ipv6 when compare asn --- blockcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockcheck.py b/blockcheck.py index b409df3..5717679 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -830,7 +830,7 @@ def main(): print("IP: {}, IPv6: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), _mask_ip(ipv6_addr), ip_isp[1])) asn4 = get_nicinfo(ip_isp[0]) asn6 = get_nicinfo(ipv6_addr) - if asn4 != asn6: + if asn4 != asn6 and not force_ipv6: ipv6_available = False print("Вероятно у вас IPv6 туннель, отключаем проверку IPv6") else: From 84b517d83c92b41fd486a08328d1cec5cd1a3f65 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Fri, 12 May 2017 12:25:52 +0300 Subject: [PATCH 4/9] update text, rename function --- blockcheck.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/blockcheck.py b/blockcheck.py index 5717679..e14a7a8 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -803,7 +803,7 @@ def check_ipv6_availability(): print(": IPv6 недоступен.") return False -def get_nicinfo(ipaddr): +def get_ispinfo(ipaddr): rdap_response = IPWhois(ipaddr) nicinfo = rdap_response.lookup_rdap(depth=1) return nicinfo @@ -828,11 +828,11 @@ def main(): if ip_isp: if ipv6_available: print("IP: {}, IPv6: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), _mask_ip(ipv6_addr), ip_isp[1])) - asn4 = get_nicinfo(ip_isp[0]) - asn6 = get_nicinfo(ipv6_addr) + asn4 = get_ispinfo(ip_isp[0]) + asn6 = get_ispinfo(ipv6_addr) if asn4 != asn6 and not force_ipv6: ipv6_available = False - print("Вероятно у вас IPv6 туннель, отключаем проверку IPv6") + print("Вероятно, у вас IPv6-туннель. Проверка IPv6 отключена.") else: print("IP: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), ip_isp[1])) print() From bb990bacd5d167b1daac10a7b20d1469237ecf1c Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Fri, 12 May 2017 12:50:54 +0300 Subject: [PATCH 5/9] return only AS number --- blockcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockcheck.py b/blockcheck.py index e14a7a8..4bb60ae 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -806,7 +806,7 @@ def check_ipv6_availability(): def get_ispinfo(ipaddr): rdap_response = IPWhois(ipaddr) nicinfo = rdap_response.lookup_rdap(depth=1) - return nicinfo + return nicinfo['asn'] def main(): ipv6_addr = None From ac79197461cbff36b77ef40d16a9464fca1ec403 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Fri, 12 May 2017 12:52:51 +0300 Subject: [PATCH 6/9] nicinfo->ispinfo --- blockcheck.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blockcheck.py b/blockcheck.py index 4bb60ae..bd37164 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -805,8 +805,8 @@ def check_ipv6_availability(): def get_ispinfo(ipaddr): rdap_response = IPWhois(ipaddr) - nicinfo = rdap_response.lookup_rdap(depth=1) - return nicinfo['asn'] + ispinfo = rdap_response.lookup_rdap(depth=1) + return ispinfo['asn'] def main(): ipv6_addr = None From 121324014468a994740ccb186c56348cc4c802f3 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Mon, 15 May 2017 13:57:39 +0300 Subject: [PATCH 7/9] try rdap --- .vscode/launch.json | 204 ++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 3 + blockcheck.py | 16 ++-- rdap-test.py | 10 +++ 4 files changed, 227 insertions(+), 6 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 rdap-test.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9f742a5 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,204 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "${workspaceRoot}", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "PySpark", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "osx": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "windows": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd" + }, + "linux": { + "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" + }, + "program": "${file}", + "cwd": "${workspaceRoot}", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Python Module", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "module": "module.name", + "cwd": "${workspaceRoot}", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Integrated Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "integratedTerminal", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "External Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${file}", + "cwd": "", + "console": "externalTerminal", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "Django", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceRoot}/manage.py", + "cwd": "${workspaceRoot}", + "args": [ + "runserver", + "--noreload" + ], + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput", + "DjangoDebugging" + ] + }, + { + "name": "Flask", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", + "cwd": "${workspaceRoot}", + "env": { + "FLASK_APP": "${workspaceRoot}/quickstart/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Flask (old)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceRoot}/run.py", + "cwd": "${workspaceRoot}", + "args": [], + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Pyramid", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "cwd": "${workspaceRoot}", + "env": {}, + "envFile": "${workspaceRoot}/.env", + "args": [ + "${workspaceRoot}/development.ini" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput", + "Pyramid" + ] + }, + { + "name": "Watson", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config:python.pythonPath}", + "program": "${workspaceRoot}/console.py", + "cwd": "${workspaceRoot}", + "args": [ + "dev", + "runserver", + "--noreload=True" + ], + "env": {}, + "envFile": "${workspaceRoot}/.env", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Attach (Remote Debug)", + "type": "python", + "request": "attach", + "localRoot": "${workspaceRoot}", + "remoteRoot": "${workspaceRoot}", + "port": 3000, + "secret": "my_secret", + "host": "localhost" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fe71598 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.linting.pylintEnabled": false +} \ No newline at end of file diff --git a/blockcheck.py b/blockcheck.py index bd37164..3bd7263 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -804,9 +804,12 @@ def check_ipv6_availability(): return False def get_ispinfo(ipaddr): - rdap_response = IPWhois(ipaddr) - ispinfo = rdap_response.lookup_rdap(depth=1) - return ispinfo['asn'] + try: + rdap_response = IPWhois(ipaddr) + ispinfo = rdap_response.lookup_rdap(depth=1) + return ispinfo['asn'] + except: + return False def main(): ipv6_addr = None @@ -830,9 +833,10 @@ def main(): print("IP: {}, IPv6: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), _mask_ip(ipv6_addr), ip_isp[1])) asn4 = get_ispinfo(ip_isp[0]) asn6 = get_ispinfo(ipv6_addr) - if asn4 != asn6 and not force_ipv6: - ipv6_available = False - print("Вероятно, у вас IPv6-туннель. Проверка IPv6 отключена.") + if not asn4 or not asn6: + if asn4 != asn6 and not force_ipv6: + ipv6_available = False + print("Вероятно, у вас IPv6-туннель. Проверка IPv6 отключена.") else: print("IP: {}, провайдер: {}".format(_mask_ip(ip_isp[0]), ip_isp[1])) print() diff --git a/rdap-test.py b/rdap-test.py new file mode 100644 index 0000000..8de1caa --- /dev/null +++ b/rdap-test.py @@ -0,0 +1,10 @@ +from ipwhois import IPWhois +from pprint import pprint + +try: + obj = IPWhois('2002::') + results = obj.lookup_rdap(depth=1) + #print (results['asn']) + pprint(results) +except: + print("somthing goes wrong") \ No newline at end of file From 1f18a128e2fe6cdf2f0f2996ff6956cc0635d11b Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Mon, 15 May 2017 14:01:33 +0300 Subject: [PATCH 8/9] clean trash --- .vscode/launch.json | 204 ------------------------------------------ .vscode/settings.json | 3 - rdap-test.py | 10 --- 3 files changed, 217 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 rdap-test.py diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 9f742a5..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,204 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Python", - "type": "python", - "request": "launch", - "stopOnEntry": false, - "pythonPath": "${config:python.pythonPath}", - "program": "${file}", - "cwd": "${workspaceRoot}", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "PySpark", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "osx": { - "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" - }, - "windows": { - "pythonPath": "${env:SPARK_HOME}/bin/spark-submit.cmd" - }, - "linux": { - "pythonPath": "${env:SPARK_HOME}/bin/spark-submit" - }, - "program": "${file}", - "cwd": "${workspaceRoot}", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "Python Module", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "module": "module.name", - "cwd": "${workspaceRoot}", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "Integrated Terminal/Console", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "program": "${file}", - "cwd": "", - "console": "integratedTerminal", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit" - ] - }, - { - "name": "External Terminal/Console", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "program": "${file}", - "cwd": "", - "console": "externalTerminal", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit" - ] - }, - { - "name": "Django", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "program": "${workspaceRoot}/manage.py", - "cwd": "${workspaceRoot}", - "args": [ - "runserver", - "--noreload" - ], - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput", - "DjangoDebugging" - ] - }, - { - "name": "Flask", - "type": "python", - "request": "launch", - "stopOnEntry": false, - "pythonPath": "${config:python.pythonPath}", - "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", - "cwd": "${workspaceRoot}", - "env": { - "FLASK_APP": "${workspaceRoot}/quickstart/app.py" - }, - "args": [ - "run", - "--no-debugger", - "--no-reload" - ], - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "Flask (old)", - "type": "python", - "request": "launch", - "stopOnEntry": false, - "pythonPath": "${config:python.pythonPath}", - "program": "${workspaceRoot}/run.py", - "cwd": "${workspaceRoot}", - "args": [], - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "Pyramid", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "cwd": "${workspaceRoot}", - "env": {}, - "envFile": "${workspaceRoot}/.env", - "args": [ - "${workspaceRoot}/development.ini" - ], - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput", - "Pyramid" - ] - }, - { - "name": "Watson", - "type": "python", - "request": "launch", - "stopOnEntry": true, - "pythonPath": "${config:python.pythonPath}", - "program": "${workspaceRoot}/console.py", - "cwd": "${workspaceRoot}", - "args": [ - "dev", - "runserver", - "--noreload=True" - ], - "env": {}, - "envFile": "${workspaceRoot}/.env", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] - }, - { - "name": "Attach (Remote Debug)", - "type": "python", - "request": "attach", - "localRoot": "${workspaceRoot}", - "remoteRoot": "${workspaceRoot}", - "port": 3000, - "secret": "my_secret", - "host": "localhost" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index fe71598..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.linting.pylintEnabled": false -} \ No newline at end of file diff --git a/rdap-test.py b/rdap-test.py deleted file mode 100644 index 8de1caa..0000000 --- a/rdap-test.py +++ /dev/null @@ -1,10 +0,0 @@ -from ipwhois import IPWhois -from pprint import pprint - -try: - obj = IPWhois('2002::') - results = obj.lookup_rdap(depth=1) - #print (results['asn']) - pprint(results) -except: - print("somthing goes wrong") \ No newline at end of file From 988e0e745551b14933299c8a1e33fda14768bef8 Mon Sep 17 00:00:00 2001 From: Nikolay Shopik Date: Mon, 15 May 2017 14:11:19 +0300 Subject: [PATCH 9/9] except on ASN lookups --- blockcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blockcheck.py b/blockcheck.py index 3bd7263..490d6a3 100755 --- a/blockcheck.py +++ b/blockcheck.py @@ -808,7 +808,7 @@ def get_ispinfo(ipaddr): rdap_response = IPWhois(ipaddr) ispinfo = rdap_response.lookup_rdap(depth=1) return ispinfo['asn'] - except: + except(ipwhois.exceptions.ASNRegistryError, ipwhois.exceptions.ASNLookupError, ASNParseError, ASNOriginLookupError): return False def main():