A Python library for Fritz!Box authentication and SMS management. This library allows you to send and receive SMS messages through your Fritz!Box router programmatically.
- ✅ Send SMS messages with configurable rate limiting
- ✅ Send SMS to multiple recipients
- ✅ Retrieve incoming SMS messages
- ✅ Two-factor authentication (TOTP) support
- ✅ Automatic session management
- ✅ Integrated rate limiting to prevent abuse
- Python 3.11+
- Fritz!Box with firmware version 8.03 or later (PBKDF2 support required)
- SMS functionality enabled on your Fritz!Box
- Valid Fritz!Box user credentials + activated TOTP with SMS permissions
from fbsmslib import FBSMSLib
# Initialize the library
fbsms = FBSMSLib(
url="http://192.168.178.1", # Your Fritz!Box IP
username="your_username",
password="your_password",
totpsecret="YOUR_TOTP_SECRET"
)
# Send a single SMS
fbsms.send_sms("+4915228895456", "Hello from Fritz!Box!")
# Get incoming SMS messages
incoming_messages = fbsms.get_sms_incoming()
for msg in incoming_messages:
print(f"From: {msg['sender']}")
print(f"Message: {msg['text']}")
print(f"Date: {msg['date']}")
print("-" * 40)The TOTP secret is required since sending SMS requires two-factor authentication to be enabled on the Fritz!Box user.
NOTE: The library is blocking and synchronous right now. The fritzbox web interface is not designed for high-frequency access. Use with caution in multi-threaded or asynchronous environments!
- Enable SMS functionality in your Fritz!Box settings
- Create a user account with SMS permissions
- Go to Fritz!Box settings → System → Fritz!Box Users
- Edit your user and enable "Authentication app"
- Scan the QR code and note the secret key
FBSMSLib(url: str, username: str, password: str, totpsecret: str, rate: Rate = None)url: Fritz!Box web interface URL (e.g., "http://192.168.178.1")username: Fritz!Box usernamepassword: Fritz!Box passwordtotpsecret: TOTP secret for 2FA (if enabled)rate: OptionalRateobject frompyrate_limiterto customize rate limiting (default is 10 SMS/hour)
Send an SMS message to a single recipient.
fbsms.send_sms("+4915228895456", "Your message here")Send an SMS message to multiple recipients with automatic delay between sends.
recipients = ["+4915228895456", "+491729925904"]
fbsms.send_sms_multiple(recipients, "Broadcast message")Get all SMS messages (sent and received).
all_messages = fbsms.get_sms()Get only incoming SMS messages.
incoming = fbsms.get_sms_incoming()from fbsmslib import FBSMSLib
fbsms = FBSMSLib(
url="http://192.168.178.1",
username="admin",
password="your_password",
totpsecret="ABCD1234EFGH5678"
)
# Send a simple message
fbsms.send_sms("+491729925904", "Hello World!")import time
from fbsmslib import FBSMSLib
fbsms = FBSMSLib(
url="http://192.168.178.1",
username="admin",
password="your_password",
totpsecret="ABCD1234EFGH5678"
)
# Check for new messages every 30 seconds
while True:
incoming = fbsms.get_sms_incoming()
for msg in incoming:
print(f"📱 New SMS from {msg['sender']}")
print(f"💬 {msg['text']}")
print(f"🕐 {msg['date']}")
print("-" * 40)
time.sleep(30)from fbsmslib import FBSMSLib
fbsms = FBSMSLib(
url="http://192.168.178.1",
username="admin",
password="your_password",
totpsecret="ABCD1234EFGH5678"
)
# Send to multiple recipients
contacts = [
"+4915228895456",
"+491729968532",
"+491749464308"
]
message = "Important announcement: Server maintenance tonight at 2 AM"
fbsms.send_sms_multiple(contacts, message)The library includes built-in rate limiting (10 SMS per hour) on a leaky bucket algorithm. The rate limit is enforced automatically, but may be customized by providing a Rate object from the pyrate_limiter library.
from fbsmslib import FBSMSLib
from pyrate_limiter import Rate, Duration
fbsms = FBSMSLib(
url="http://192.168.178.1",
username="admin",
password="your_password",
totpsecret="ABCD1234EFGH5678",
rate=Rate(2, Duration.MINUTE) # Custom rate limit: 2 SMS per minute
)
# The library will automatically enforce these rate limits
try:
for i in range(3): # Try to send 15 messages
fbsms.send_sms("+491749464308", f"Message {i}")
except RuntimeError as e:
print(f"Rate limit hit: {e}")Common exceptions you might encounter:
RuntimeError: Rate limit exceeded or network issuesException: Authentication failures or Fritz!Box communication errorsNotImplementedError: Unsupported 2FA methods
-
"FRITZ!Box does not support PBKDF2"
- Update your Fritz!Box firmware to version 7.24 or later
-
"wrong username or password"
- Verify your credentials
- Ensure the user has SMS permissions
-
Rate limit exceeded
- Wait for the rate limit window to reset
- Consider batching messages with delays
-
Connection errors
- Verify Fritz!Box IP address and network connectivity
- Check if Fritz!Box web interface is accessible
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
This library is not affiliated with FRITZ! GmbH. Fritz!Box is a trademark of FRITZ! GmbH. Use this library responsibly and in accordance with your local telecommunications regulations.