Created
August 13, 2019 12:23
-
-
Save steven-p-walsh/9b7c0ffd2fe4817d6745951766f5a0f0 to your computer and use it in GitHub Desktop.
Social Media Shock Collar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from scapy.all import * | |
import sys, ifaddr, os | |
bad_sites = [ | |
'reddit.com', | |
'youtube.com', | |
'news.ycombinator.com', | |
'wsj.com', | |
'theintercept.com', | |
'facebook.com', | |
'twitter.com' | |
] | |
def check_match(dns_name): | |
# just so it's eaiser to add domains | |
if dns_name.startswith('www.'): | |
dns_name = dns_name[4:] | |
# if it's a bad domain, let's shock the user | |
if dns_name in bad_sites: | |
print '%s is a bad domain' % dns_name | |
os.system('play -n synth .5 sin 1500') | |
def get_adapter_name(): | |
# get the first available adapter | |
adapters = ifaddr.get_adapters() | |
for adapter in adapters: | |
if len(adapter.ips) > 0 and adapter.ips[0].ip != '127.0.0.1': | |
return adapter.name | |
# listen for dns requests | |
def querysniff(pkt): | |
if IP in pkt: | |
ip_src = pkt[IP].src | |
ip_dst = pkt[IP].dst | |
if pkt.haslayer(DNS) and pkt.getlayer(DNS).qr == 0: | |
check_match(pkt.getlayer(DNS).qd.qname[:-1]) | |
interface = get_adapter_name() | |
print 'using interface: %s' % interface | |
sniff(iface = interface,filter = "port 53", prn = querysniff, store = 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very cool script, here's a quick python3 translation for others: