Euronymou5

Whitelist via IP in python

Sep 27th, 2022
1,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. # Recommended to use an obfuscator in case of using it
  2.  
  3. import requests
  4. import time
  5.  
  6. def main(): # inside here should go the main code of the program
  7.   print('\nWhitelisted.')
  8.  
  9. resp = requests.get('http://ip-api.com/json/').json() # here we make a get request to the ip-api.com page to obtain the user's ip
  10.  
  11. ip = resp['query'] # here we save the user's ip in the ip variable
  12.  
  13. whitelist_ip = [ # Our list that we will use to put the IPs inside
  14.   "185.8.63.38", # Here inside will be the IP of the people who will be able to execute the main function (main)
  15.   "169.254.0.1",
  16. ]
  17.  
  18. if ip in whitelist_ip: # Here we check if the ip of the variable is in our list
  19.   print(f'Verifying IP: {ip}')
  20.   time.sleep(3)
  21.   print('Verified IP.')
  22.   time.sleep(2)
  23.   menu() # Here we execute the main function verifying that the user's IP is in the whitelisted IP list
  24. else:
  25.   print(f'Verifying IP: {ip}')
  26.   time.sleep(3)
  27.   print('You are not on the white list!')
  28.   exit() # Here we make an output by verifying that the user's IP is not in our list of whitelisted IPs
Advertisement
Add Comment
Please, Sign In to add comment