Skip to content

Commit

Permalink
Fix number verification
Browse files Browse the repository at this point in the history
  • Loading branch information
sundowndev committed Oct 25, 2018
1 parent 1e05d6a commit b0d6380
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions phoneinfoga.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python

import sys
import hashlib
import json
from bs4 import BeautifulSoup

try:
import requests
import requests
import sys
import hashlib
import json
from bs4 import BeautifulSoup
except:
print "Request library not found, please install it before proceeding\n"
sys.exit()
Expand All @@ -27,46 +26,53 @@ def help():
print " -n|--number: Phone number to search"
print " -h|--help: Help command"

def getInformations(PhoneNumber):
# verify input type
if str.isdigit(PhoneNumber) != True:
print("\033[31mError: please enter a valid integer as value")
sys.exit()

print("Fetching information for number +" + PhoneNumber + "...")

# get scl_request_secret
def getRequestSecret():
requestSecret = ''
resp = requests.get('https://numverify.com/')
soup = BeautifulSoup(resp.text, "html5lib")
for tag in soup.find_all("input", type="hidden"):
if tag['name'] == "scl_request_secret":
requestSecret = tag['value']
break;

return requestSecret

apiKey = hashlib.md5(PhoneNumber + requestSecret).hexdigest()
def getInformations(PhoneNumber):
# verify input type
if str.isdigit(PhoneNumber) != True:
print("\033[31mError: please enter a valid integer.")
sys.exit()

print("Fetching information for number +" + PhoneNumber + "...")

apiKey = hashlib.md5(PhoneNumber + getRequestSecret()).hexdigest()

response = requests.get("https://numverify.com/php_helper_scripts/phone_api.php?secret_key=" + apiKey + "&number=" + PhoneNumber)
if response.content == "Unauthorized" or response.status_code != 200:
print("An error occured while calling the API (bad request or wrong api key).")
sys.exit()

data = json.loads(response.content)

if data["valid"] == False:
print("\033[31mError: the number +" + PhoneNumber + " is not valid.")
print("Be sure to use the correct format : (+)1 415-858-6273 (without spaces)\033[94m")

try:
data["valid"] == True
except:
print("\033[31mError: Please specify a phone number. " + PhoneNumber + " is not valid.")
print("Example: 14158586273\033[94m")
sys.exit()
else:
print "\n"
print "\033[1;32m1 result found for (" + data["country_prefix"] + ") " + data["local_format"]
print "\n"
print("[Country] " + data["country_name"] + "(" + data["country_code"] + ")")
print("[Carrier] " + data["carrier"])
print("[Line type] " + data["line_type"])

print "\n"
print "\033[1;32m1 result found for (" + data["country_prefix"] + ") " + data["local_format"]
print "\n"
print("[Country] " + data["country_name"] + "(" + data["country_code"] + ")")
print("[Carrier] " + data["carrier"])
print("[Line type] " + data["line_type"])

if sys.argv[1:][0] == "-n" or sys.argv[1:][0] == "--number":
PhoneNumber = sys.argv[1:][1]
getInformations(PhoneNumber)
else:
try:
sys.argv[1:][0] == "-n" or sys.argv[1:][0] == "--number"
except:
help()
sys.exit()
else:
PhoneNumber = sys.argv[1:][1]
getInformations(PhoneNumber)

0 comments on commit b0d6380

Please sign in to comment.