Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Created October 4, 2012 00:43
Show Gist options
  • Save TMcManus/3830824 to your computer and use it in GitHub Desktop.
Save TMcManus/3830824 to your computer and use it in GitHub Desktop.
Risky Account Finder

Installation and Use

  1. In a python environment that has pip installed, do pip install twilio then pip install phonenumbers.
  2. Do python risky-account-finder.py
from twilio.rest import TwilioRestClient
import phonenumbers
ACCOUNT_SID = "ACXXXXXXX" // Your Account SID
AUTH_TOKEN = "YYYYYYY" //Your Auth Token
# List the country codes you want to check for here
risky_countries = ['370', '359', '355', '381', '509', '994', '297', '232']
def figure_out_country(phone_number):
try:
x = phonenumbers.parse(phone_number, None)
return str(x.country_code)
# Don't fail on the numerous exceptions
except phonenumbers.phonenumberutil.NumberParseException:
return "Other"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
subaccounts = client.accounts.list()
for subaccount in subaccounts:
call_list = subaccount.calls.list()
for call in call_list:
country_code = figure_out_country(call.to)
if country_code in risky_countries:
print "%s|%s|%s|%s|%s" % (country_code, call.to, subaccount.friendly_name, subaccount.sid, subaccount.status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment