Last active
December 3, 2021 20:55
-
-
Save Alistair1231/1bab8ffb8ee7222a0ba33590cc9679a4 to your computer and use it in GitHub Desktop.
reconnect nordvpn until good IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import time | |
| import requests | |
| from bs4 import BeautifulSoup as bs | |
| import subprocess | |
| def jaNein(what): | |
| if what == "Ja": | |
| return True | |
| else: | |
| return False | |
| def getCurrentIp(): | |
| return requests.get("http://ipinfo.io/ip").text | |
| def getNewIp(): | |
| currentIp = getCurrentIp() | |
| print("Current IP: " + currentIp) | |
| os.system('"C:\\Program Files\\NordVPN\\NordVPN.exe" -c') | |
| #check if online | |
| while True: | |
| time.sleep(1) | |
| try: | |
| requests.get("https://google.com") | |
| break | |
| except: | |
| print("Waiting for NordVPN to connect...") | |
| newIp = getCurrentIp() | |
| print("New IP: " + newIp) | |
| # if Ip did change, check if it is good | |
| if(currentIp != newIp): | |
| if not checkWhoer(): | |
| getNewIp() | |
| if not checkIpInfo(): | |
| getNewIp() | |
| else: | |
| getNewIp() | |
| def checkIpInfo(): | |
| #privacy detection via ipinfo.io | |
| url = "https://ipinfo.io/products/proxy-vpn-detection-api" | |
| params={ | |
| 'landing-tryit-search-input': getCurrentIp() | |
| } | |
| session = requests.Session() | |
| response = session.get(url, params=params) | |
| soup = bs(response.content, "html.parser") | |
| result = soup.find("div", class_="tryit-data").find_all("i", class_="icon-privacy") | |
| vals = { | |
| "vpn": len(result[0].contents) == 1, | |
| "proxy": len(result[1].contents) == 1, | |
| "tor": len(result[2].contents) == 1, | |
| "relay": len(result[3].contents) == 1, | |
| "hosting": len(result[4].contents) == 1, | |
| } | |
| print("IpInfo: VPN/Proxy/Tor/Relay/Hosting: \t" + str(vals["vpn"]) + "/" + str(vals["proxy"]) + "/" + str(vals["tor"]) + "/" + str(vals["relay"]) + "/" + str(vals["hosting"])) | |
| # everything must be undetected except hosting | |
| if(not vals["vpn"] and not vals["proxy"] and not vals["tor"] and not vals["relay"]): | |
| return True | |
| def checkWhoer(): | |
| URL = "https://whoer.net/de" | |
| page = requests.get(URL) | |
| # get text in span with class cont and proxy-status-message | |
| soup = bs(page.content, "html.parser") | |
| isProxy=jaNein(soup.select("span.cont.proxy-status-message")[0].contents[0].replace("\n", "")=="Nein") | |
| isAnonymizer = jaNein(soup.find("div", id="anonymizer").find("span", class_="value").contents[0].replace("\n", "")) | |
| isBlacklist = jaNein(soup.find("div", id="blStatus").find("a").contents[0].replace("\n", "")) | |
| print("Whoer: is Proxy/Anonymizer/Blacklist: \t" + str(isProxy) + "/" + str(isAnonymizer) + "/" + str(isBlacklist)) | |
| # if all 3 false, then return true | |
| isGoodIp = ((not isProxy) and (not isAnonymizer) and (not isBlacklist)) | |
| return isGoodIp | |
| if __name__ == '__main__': | |
| getNewIp() | |
| # generate exe via auto-py-to-exe | |
| # https://towardsdatascience.com/how-to-easily-convert-a-python-script-to-an-executable-file-exe-4966e253c7e9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment