sms_broadcast.py
· 1.9 KiB · Python
Surowy
#!/usr/bin/env python
import telnetlib
import sqlite3
import sys
imsi = 999999999999999
HLR_DATABASE = "configs/hlr.sqlite3"
def check_extension(extension):
conn.write(b"show subscriber extension %s\n" % extension)
res = conn.read_until(b"OpenBSC> ")
if b"No subscriber found for extension" in res:
create_subscriber(extension)
def create_subscriber(extension):
print("No user with excension %s found. Creating new..." % extension)
print("Extension: %s, IMSI: %d" % (extension, imsi))
conn.write(b"show subscriber imsi %d\n" % imsi)
res = conn.read_until(b"OpenBSC> ")
if b"No subscriber found for imsi" in res:
conn.write(b"subscriber create imsi %d\n" % imsi)
conn.read_until(b"OpenBSC> ")
conn.write(b"enable\n")
conn.read_until(b"OpenBSC# ")
conn.write(b"subscriber imsi %d extension %s\n" % (imsi, extension))
conn.read_until(b"OpenBSC# ")
conn.write(b"disable\n")
conn.read_until(b"OpenBSC> ")
def get_users():
# returns user id list generator
db = sqlite3.connect(HLR_DATABASE)
c = db.cursor()
c.execute("SELECT * FROM Subscriber")
for subscriber in c.fetchall():
yield subscriber[0]
def send_sms(id, extension, message):
conn.write(b"subscriber id %d sms sender extension %s send %s\n" % (id, extension, message))
res = conn.read_until(b"OpenBSC> ")
if b"%" in res:
print(res)
exit(1)
if __name__ == "__main__":
try:
extension = sys.argv[1]
message = " ".join(sys.argv[2:])
except:
print("usage: ./sms_broadcast.py extension message")
print("This script sends a message from the specified extension (number) to all devices connected to this base station")
exit(1)
conn = telnetlib.Telnet("127.0.0.1", 4242)
conn.read_until(b"OpenBSC> ")
check_extension(extension)
for id in get_users():
send_sms(id, extension, message)
| 1 | #!/usr/bin/env python |
| 2 | import telnetlib |
| 3 | import sqlite3 |
| 4 | import sys |
| 5 | |
| 6 | imsi = 999999999999999 |
| 7 | HLR_DATABASE = "configs/hlr.sqlite3" |
| 8 | |
| 9 | def check_extension(extension): |
| 10 | conn.write(b"show subscriber extension %s\n" % extension) |
| 11 | res = conn.read_until(b"OpenBSC> ") |
| 12 | |
| 13 | if b"No subscriber found for extension" in res: |
| 14 | create_subscriber(extension) |
| 15 | |
| 16 | def create_subscriber(extension): |
| 17 | print("No user with excension %s found. Creating new..." % extension) |
| 18 | print("Extension: %s, IMSI: %d" % (extension, imsi)) |
| 19 | |
| 20 | conn.write(b"show subscriber imsi %d\n" % imsi) |
| 21 | res = conn.read_until(b"OpenBSC> ") |
| 22 | |
| 23 | if b"No subscriber found for imsi" in res: |
| 24 | conn.write(b"subscriber create imsi %d\n" % imsi) |
| 25 | conn.read_until(b"OpenBSC> ") |
| 26 | |
| 27 | conn.write(b"enable\n") |
| 28 | conn.read_until(b"OpenBSC# ") |
| 29 | conn.write(b"subscriber imsi %d extension %s\n" % (imsi, extension)) |
| 30 | conn.read_until(b"OpenBSC# ") |
| 31 | conn.write(b"disable\n") |
| 32 | conn.read_until(b"OpenBSC> ") |
| 33 | |
| 34 | def get_users(): |
| 35 | # returns user id list generator |
| 36 | |
| 37 | db = sqlite3.connect(HLR_DATABASE) |
| 38 | c = db.cursor() |
| 39 | c.execute("SELECT * FROM Subscriber") |
| 40 | |
| 41 | for subscriber in c.fetchall(): |
| 42 | yield subscriber[0] |
| 43 | |
| 44 | def send_sms(id, extension, message): |
| 45 | conn.write(b"subscriber id %d sms sender extension %s send %s\n" % (id, extension, message)) |
| 46 | res = conn.read_until(b"OpenBSC> ") |
| 47 | if b"%" in res: |
| 48 | print(res) |
| 49 | exit(1) |
| 50 | |
| 51 | if __name__ == "__main__": |
| 52 | try: |
| 53 | extension = sys.argv[1] |
| 54 | message = " ".join(sys.argv[2:]) |
| 55 | except: |
| 56 | print("usage: ./sms_broadcast.py extension message") |
| 57 | print("This script sends a message from the specified extension (number) to all devices connected to this base station") |
| 58 | exit(1) |
| 59 | |
| 60 | conn = telnetlib.Telnet("127.0.0.1", 4242) |
| 61 | conn.read_until(b"OpenBSC> ") |
| 62 | |
| 63 | check_extension(extension) |
| 64 | |
| 65 | for id in get_users(): |
| 66 | send_sms(id, extension, message) |
| 67 |
sms_spam.py
· 1.7 KiB · Python
Surowy
#!/usr/bin/env python
import telnetlib
import sys
import random
import time
imsi = 999999999999999
def check_extension(extension):
conn.write(b"show subscriber extension %s\n" % extension)
res = conn.read_until(b"OpenBSC> ")
if b"No subscriber found for extension" in res:
print("Phone with extension %s not found ;(" % extension)
exit(1)
def check_spam_subscriber():
conn.write(b"show subscriber imsi %d\n" % imsi)
res = conn.read_until(b"OpenBSC> ")
if b"No subscriber found for imsi" in res:
conn.write(b"subscriber create imsi %d\n" % imsi)
print(conn.read_until(b"OpenBSC> "))
def send(extension, spam_number, message):
print("Sending sms from %d..." % spam_number)
conn.write(b"enable\n")
conn.read_until(b"OpenBSC# ")
conn.write(b"subscriber imsi %d extension %d\n" % (imsi, spam_number))
conn.read_until(b"OpenBSC# ")
conn.write(b"disable\n")
conn.read_until(b"OpenBSC> ")
conn.write(b"subscriber extension %s sms sender extension %d send %s\n" % (extension, spam_number, message))
res = conn.read_until(b"OpenBSC> ")
if b"%" in res:
print(res)
exit(1)
if __name__ == "__main__":
try:
extension = sys.argv[1]
repeats = int(sys.argv[2])
message = " ".join(sys.argv[3:])
except:
print("usage: ./sms_spam.py extension [num of repeats] message")
print("This script sends a message to specified number")
exit(1)
conn = telnetlib.Telnet("127.0.0.1", 4242)
conn.read_until(b"OpenBSC> ")
check_extension(extension)
check_spam_subscriber()
for _ in range(repeats):
spam_number = random.randint(1000,9999)
send(extension, spam_number, message)
time.sleep(2)
| 1 | #!/usr/bin/env python |
| 2 | import telnetlib |
| 3 | import sys |
| 4 | import random |
| 5 | import time |
| 6 | |
| 7 | imsi = 999999999999999 |
| 8 | |
| 9 | def check_extension(extension): |
| 10 | conn.write(b"show subscriber extension %s\n" % extension) |
| 11 | res = conn.read_until(b"OpenBSC> ") |
| 12 | |
| 13 | if b"No subscriber found for extension" in res: |
| 14 | print("Phone with extension %s not found ;(" % extension) |
| 15 | exit(1) |
| 16 | |
| 17 | def check_spam_subscriber(): |
| 18 | conn.write(b"show subscriber imsi %d\n" % imsi) |
| 19 | res = conn.read_until(b"OpenBSC> ") |
| 20 | |
| 21 | if b"No subscriber found for imsi" in res: |
| 22 | conn.write(b"subscriber create imsi %d\n" % imsi) |
| 23 | print(conn.read_until(b"OpenBSC> ")) |
| 24 | |
| 25 | def send(extension, spam_number, message): |
| 26 | print("Sending sms from %d..." % spam_number) |
| 27 | |
| 28 | conn.write(b"enable\n") |
| 29 | conn.read_until(b"OpenBSC# ") |
| 30 | conn.write(b"subscriber imsi %d extension %d\n" % (imsi, spam_number)) |
| 31 | conn.read_until(b"OpenBSC# ") |
| 32 | conn.write(b"disable\n") |
| 33 | conn.read_until(b"OpenBSC> ") |
| 34 | |
| 35 | conn.write(b"subscriber extension %s sms sender extension %d send %s\n" % (extension, spam_number, message)) |
| 36 | res = conn.read_until(b"OpenBSC> ") |
| 37 | |
| 38 | if b"%" in res: |
| 39 | print(res) |
| 40 | exit(1) |
| 41 | |
| 42 | if __name__ == "__main__": |
| 43 | try: |
| 44 | extension = sys.argv[1] |
| 45 | repeats = int(sys.argv[2]) |
| 46 | message = " ".join(sys.argv[3:]) |
| 47 | except: |
| 48 | print("usage: ./sms_spam.py extension [num of repeats] message") |
| 49 | print("This script sends a message to specified number") |
| 50 | exit(1) |
| 51 | |
| 52 | conn = telnetlib.Telnet("127.0.0.1", 4242) |
| 53 | conn.read_until(b"OpenBSC> ") |
| 54 | |
| 55 | check_extension(extension) |
| 56 | check_spam_subscriber() |
| 57 | |
| 58 | for _ in range(repeats): |
| 59 | spam_number = random.randint(1000,9999) |
| 60 | send(extension, spam_number, message) |
| 61 | time.sleep(2) |
| 62 |