from http.server import BaseHTTPRequestHandler, HTTPServer
key = "YOUR_API_KEY_HERE"
def proxy_vpn_api(self, ip: str, vars: dict = {}) -> dict:
"""Method used to lookup Proxy & VPN Detection API
ip (str): IPv4 or IPV6 to lookup.
vars (dict, optional): Reffer to https://www.ipqualityscore.com/documentation/proxy-detection-api/address-validation for variables. Defaults to {}.
dict: Returns json response in an array.
url = "https://www.ipqualityscore.com/api/json/ip/%s/%s" % (self.key, ip)
x = requests.get(url, params = vars)
return (json.loads(x.text))
class MyServer(BaseHTTPRequestHandler):
"""This is an example basic web server. we limited it to handle "/" path only."""
header_items= dict(self.headers.items())
'user_agent' : header_items['User-Agent'],
'user_language' : header_items['Accept-Language'].split(',')[0],
'allow_public_access_points' : 1,
transaction_parameters = {
User & Transaction Scoring
Score additional information from a user, order, or transaction for risk analysis
All transaction parameters are optional, please remove any that are not used
Non paid actions such as lead generation and user scoring can be substituted into the "billing" or "shipping" variables
This feature requires a Premium plan or greater
Premium users can also adjust transaction scoring rules: https://www.ipqualityscore.com/user/transaction/weights
Optionally pass up to 2 phone numbers per user or transaction
Countries are optional - 2 letter country code can be included if country code is not included in the phone number
transaction_parameters = {
result = ipqs.proxy_vpn_api(self.client_address[0],{**parameters, **transaction_parameters})
if 'success' in result and result['success'] == True:
# Phone Reputation Scoring Example 1: We'd like to block users with an invalid phone number or high risk phone number that was recently associated with an abusive account
if $result['transaction_details']['valid_billing_phone'] == False || $result['transaction_details']['valid_shipping_phone'] == False || $result['transaction_details']['risky_billing_phone'] == True || $result['transaction_details']['risky_shipping_phone'] == True:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
# Phone Reputation Scoring Example 2: We'd like to block users with any occurrence of high risk behavior or an overall Fraud Score >= 90
if $result['fraud_score'] >= 90 || $result['transaction_details']['fraudulent_behavior'] == True:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
# Phone Reputation Scoring Example 3: We'd like to block users with an overall Fraud Score >= 90, users with VPN connections, or users with an invalid or abusive phone number
if $result['fraud_score'] >= 90 || $result['vpn'] == True || $result['transaction_details']['valid_billing_phone'] == False || $result['transaction_details']['valid_shipping_phone'] == False || $result['transaction_details']['risky_billing_phone'] == True || $result['transaction_details']['risky_shipping_phone'] == True:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
If you are confused with these examples or simply have a use case
not covered here, please feel free to contact IPQualityScore's support
team. We'll craft a custom piece of code to meet your requirements.
self.send_header("Content-type", "text/html")
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
webServer.serve_forever()
except KeyboardInterrupt: