Skip to content

Instantly share code, notes, and snippets.

@Ap0dexMe0
Created July 17, 2025 09:22
Show Gist options
  • Select an option

  • Save Ap0dexMe0/4723cbfc162d7206ffcd6f1821049ac9 to your computer and use it in GitHub Desktop.

Select an option

Save Ap0dexMe0/4723cbfc162d7206ffcd6f1821049ac9 to your computer and use it in GitHub Desktop.
Phone Number Tracker with Location and Carrier Detection (Malaysia Optimized)
import phonenumbers
from phonenumbers import geocoder, carrier
from opencage.geocoder import OpenCageGeocode
import re
import folium
import webbrowser
import os
# -----------------------------------------
# πŸ“˜ Custom carrier resolver for Malaysia
# -----------------------------------------
def resolve_malaysian_carrier(phone_number):
raw = phone_number.replace("+6", "") # Malaysia country code
prefix = raw[:3] if raw.startswith("011") else raw[:3]
subprefix = int(raw[3:6]) if raw.startswith("011") else int(raw[3])
# Carrier map (partial sample, can be extended)
carrier_map = {
"010": {
"2": "Celcom", "36": "Celcom", "37": "Celcom", "38": "Celcom", "39": "Celcom",
"40": "Celcom", "41": "Celcom", "42": "Maxis", "43": "Maxis", "44": "UniFi Mobile",
"45": "UniFi Mobile", "46": "Celcom", "50": "Tune Talk", "51": "Tune Talk"
},
"011": {
100: "UniFi Mobile", 105: "redONE", 11: "U Mobile", 12: "Maxis", 13: "XOX",
140: "Maxis", 145: "Celcom", 150: "Tune Talk", 16: "DiGi", 170: "Yes 4G",
180: "Telekom Malaysia", 200: "Tron", 34: "BuzzME", 38: "Friendi"
},
"012": { "2": "Maxis", "9": "Maxis" },
"013": { "2": "Celcom", "9": "Celcom" },
"014": { "2": "Maxis", "3": "DiGi", "4": "Tune Talk", "5": "Celcom", "7": "Maxis" },
"016": { "2": "DiGi", "9": "DiGi" },
"017": { "2": "Maxis", "9": "Maxis" },
"018": { "2": "U Mobile", "3": "Yes 4G" },
"019": { "2": "Celcom", "9": "Celcom" },
}
if prefix in carrier_map:
carrier_ranges = carrier_map[prefix]
if raw.startswith("011"):
return carrier_ranges.get(subprefix, "Unknown")
else:
return carrier_ranges.get(str(subprefix), "Unknown")
return "Unknown"
# -----------------------------------------
# πŸ“ Main Tracking Function
# -----------------------------------------
def track_and_geocode(phone_number, api_key):
try:
parsed_number = phonenumbers.parse(phone_number)
except phonenumbers.phonenumberutil.NumberParseException as e:
return f"❌ Invalid phone number format: {e}"
country_location = geocoder.description_for_number(parsed_number, "en")
sim_carrier_raw = carrier.name_for_number(parsed_number, "en")
custom_carrier = resolve_malaysian_carrier(phone_number)
geocoder_oc = OpenCageGeocode(api_key)
# Forward geocode
forward_results = geocoder_oc.geocode(country_location)
if not forward_results:
return "❌ Forward geocoding failed."
latitude = forward_results[0]['geometry']['lat']
longitude = forward_results[0]['geometry']['lng']
# Reverse geocode
reverse_results = geocoder_oc.reverse_geocode(latitude, longitude)
if not reverse_results:
formatted_address = "❌ Reverse geocoding failed."
else:
formatted_address = reverse_results[0]['formatted']
# Create map with folium
location_map = folium.Map(location=[latitude, longitude], zoom_start=7)
folium.Marker(
[latitude, longitude],
tooltip="πŸ“ Phone Number Region",
popup=formatted_address
).add_to(location_map)
map_filename = "phone_location_map.html"
location_map.save(map_filename)
webbrowser.open('file://' + os.path.realpath(map_filename))
return {
"Phone Number": phone_number,
"Carrier (Library)": sim_carrier_raw or "Unavailable",
"Carrier (Custom Detected)": custom_carrier,
"Region from Number": country_location,
"Latitude": latitude,
"Longitude": longitude,
"Reverse Geocoded Address": formatted_address,
"Google Maps": f"https://www.google.com/maps?q={latitude},{longitude}",
"Map File": map_filename
}
# -----------------------------------------
# πŸš€ Entry Point
# -----------------------------------------
if __name__ == "__main__":
api_key = "" # YOUR API KEY
phone = input("πŸ“± Enter phone number (with +countrycode): ").strip()
result = track_and_geocode(phone, api_key)
print("\nπŸ” Tracking Result:\n")
if isinstance(result, dict):
for key, val in result.items():
print(f"{key}: {val}")
else:
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment