---
title: "How to Detect SIM Swaps in Rust With Twilio's Lookup API"
description: "SIM swap attacks let attackers take over a phone number by convincing the carrier to link it to a new SIM, enabling them to receive all calls and SMS, including OTP codes for two-factor authentication. Twilio’s Lookup API provides real-time SIM swap data from mobile network operators, indicating if the SIM linked to a number has recently changed. This tutorial shows how to integrate SIM swap detection into Rust using the rustlio crate, with dependencies dotenvy, serde, serde_json, and tokio. The code loads environment variables from a .env file for Twilio Account SID and Auth Token, calls lookup_phone_data with DataPackage::SimSwap, and prints the last_sim_swap date (e.g., 2020-04-27T10:18:50Z), swapped_period (e.g., PT48H), and swapped_in_period boolean. The post notes legitimate SIM swaps happen for reasons like lost phones or porting numbers, so the data should always be used as part of a larger, more holistic determination rather than alone."
---

# How to Detect SIM Swaps in Rust With Twilio's Lookup API

[Twilio](https://yomu.fyi/company/twilio) · Matthew Setter · Oct 19, 2026

**Type:** Tutorial

## Summary

SIM swap attacks let attackers take over a phone number by convincing the carrier to link it to a new SIM, enabling them to receive all calls and SMS, including OTP codes for two-factor authentication. Twilio’s Lookup API provides real-time SIM swap data from mobile network operators, indicating if the SIM linked to a number has recently changed. This tutorial shows how to integrate SIM swap detection into Rust using the rustlio crate, with dependencies dotenvy, serde, serde\_json, and tokio. The code loads environment variables from a .env file for Twilio Account SID and Auth Token, calls lookup\_phone\_data with DataPackage::SimSwap, and prints the last\_sim\_swap date (e.g., 2020-04-27T10:18:50Z), swapped\_period (e.g., PT48H), and swapped\_in\_period boolean. The post notes legitimate SIM swaps happen for reasons like lost phones or porting numbers, so the data should always be used as part of a larger, more holistic determination rather than alone.

## Context

SIM swap attacks compromise SMS-based two-factor authentication by allowing attackers to take over a phone number. Twilio’s Lookup API offers SIM swap detection using real-time data from mobile network operators. This tutorial shows how to use it in Rust.

## Approach / What changed

Create a Rust binary project, add crates dotenvy, rustlio, serde, serde\_json, and tokio. Set environment variables for Twilio Account SID and Auth Token in a .env file. Write code that loads the .env, calls lookup\_phone\_data with DataPackage::SimSwap, and prints the last\_sim\_swap result. Run with cargo run.

## Takeaways

- SIM swap attacks allow attackers to receive OTP codes sent via SMS by taking over the victim’s phone number through the carrier.
- Twilio’s Lookup API provides real-time SIM swap data directly from mobile network operators, indicating if the SIM has recently changed.
- SIM swap data should be used as part of a larger risk assessment because legitimate swaps occur for reasons like lost phones, porting numbers, or new phones.

## FAQ

### What is a SIM swap attack?

A SIM swap attack occurs when an attacker convinces a mobile telecom provider to link a victim's phone number to a SIM card under the attacker's control, allowing them to receive calls and SMS, including OTP codes.

### How does Twilio's Lookup API detect SIM swaps?

The Lookup API provides real-time authoritative data sourced from mobile network operators that tells you if the SIM linked to a phone number has recently changed, helping assess risk.

### What are legitimate reasons for a SIM swap?

Legitimate reasons include losing your phone or having it stolen, porting your number to a different carrier, or buying a new phone.

**Tags:** [Rust](https://yomu.fyi/topic/rust), [Security](https://yomu.fyi/topic/security), [SIM Swap](https://yomu.fyi/topic/sim-swap), [Twilio](https://yomu.fyi/topic/twilio)

- Source: [Twilio](https://www.twilio.com/en-us/blog/developers/tutorials/detect-sim-swaps-rust-twilio-lookup-api)
- Source URL: https://www.twilio.com/en-us/blog/developers/tutorials/detect-sim-swaps-rust-twilio-lookup-api
- Ingested by Yomu: 2026-10-19T06:00:14.477Z

[Read original post](https://www.twilio.com/en-us/blog/developers/tutorials/detect-sim-swaps-rust-twilio-lookup-api)
