├── pns.png
├── README.md
├── pns.py
└── index.html
/pns.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DrummerHead/UKPR0nFilter/master/pns.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | So i hear the UK government wants to make a porn filter. About bloody time i reckon. I'm fed up of happily browsing the Internet for boobs, only to have non-porn related subject matter thrust down my face hole.
3 |
4 | So taking inspiration from other great Internet filtering nations such as [North Korea, China, Syria, Iran, Cuba, Bahrain, Belarus, Burma, Uzbekistan, Saudia Arabia and Vietnam](http://en.wikipedia.org/wiki/Internet_censorship_by_country) I decided to help out the UK government and build an Internet filter that only allows pornographic material through.
5 |
6 | You're Welcome.
7 |
8 |
9 | Setting Up
10 | ==========
11 | All code is available here [https://github.com/SickSad/UKPR0nFilter](https://github.com/SickSad/UKPR0nFilter)
12 |
13 | Just follow this simple step-by-step video walk-through and you'll have a porn filter running in no time!
14 | [http://www.youtube.com/watch?v=xJfyNwM6Lw8](http://www.youtube.com/watch?v=xJfyNwM6Lw8)
15 |
16 | Nerd Stuff
17 | ==========
18 |
19 | The filter is a dns server which checks all queries against the [OpenDNS](http://www.opendns.com/home-solutions/parental-controls/) FamilySheild DNS server. Any request that is denied by OpenDNS is then allowed by our DNS server, and any request allowed by OpenDNS is blocked by us.
20 |
21 | The server itself it built using the [python Twisted framework](http://twistedmatrix.com/) which handles both the DNS requests and acts as a simple web-server to host the denial page.
--------------------------------------------------------------------------------
/pns.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # pns.py is a simple DNS server which only allows pornagraphic material through.
4 | #
5 | # Bits and pieces robbed from here:
6 | # https://gist.github.com/johnboxall/1147973
7 | # http://twistedmatrix.com/trac/wiki/TwistedWeb
8 | import socket
9 | import dns.resolver as DNS
10 |
11 | from twisted.internet.protocol import Factory, Protocol
12 | from twisted.internet import reactor
13 | from twisted.names import dns
14 | from twisted.names import client, server
15 | from twisted.web import server as webserver
16 | from twisted.web import resource
17 | import sys
18 | index = open('index.html').read()
19 |
20 | class Simple(resource.Resource):
21 | isLeaf = True
22 | def render_GET(self, request):
23 | return index
24 |
25 |
26 | class DNSServerFactory(server.DNSServerFactory):
27 |
28 | def gotResolverResponse(self, (ans, auth, add), protocol, message, address):
29 | qname = message.queries[0].name.name
30 | print qname
31 | blocked_resolver = DNS.Resolver()
32 | blocked_resolver.nameservers = ['208.67.222.123','208.67.220.123']
33 |
34 |
35 | porn = False
36 | results = blocked_resolver.query(qname)
37 | for r in results:
38 | print r
39 | if str(r).startswith('67.215.65'):
40 | print "PRON"
41 | porn = True
42 |
43 | if porn == False:
44 | print "NOT PRON"
45 | for answer in ans:
46 | if answer.type != dns.A:
47 | continue
48 | answer.payload.address = socket.inet_aton(ip_address)
49 | answer.payload.ttl = 60
50 | #address = ('127.0.0.1', 43160)
51 | args = (self, (ans, auth, add), protocol, message, address)
52 | result=server.DNSServerFactory.gotResolverResponse(*args)
53 | print result
54 | return result
55 |
56 |
57 | verbosity = 0
58 |
59 | ip_address = ""
60 | if len(sys.argv) > 1:
61 | ip_address = sys.argv[1]
62 | else:
63 | ip_address = '127.0.0.1'
64 |
65 | resolver = client.Resolver(servers=[('8.8.8.8', 53)])
66 | factory = DNSServerFactory(clients=[resolver], verbose=verbosity)
67 | protocol = dns.DNSDatagramProtocol(factory)
68 | factory.noisy = protocol.noisy = verbosity
69 |
70 | reactor.listenUDP(53, protocol)
71 | reactor.listenTCP(53, factory)
72 | site = webserver.Site(Simple())
73 | reactor.listenTCP(8080, site)
74 | reactor.run()
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Unauthorized non-porn blocked
5 |
6 |
29 |
30 |
31 |
32 | THE GREAT FIREWALL OF PORN
33 | You appear to want to view content of a non-pornographic nature. This request has been monitored.
34 | Under new government legislation the Internet is only for porn.
35 | Until you file a N0NPR0n.32b "Request To Access Material Of A Non-Pornographic Nature" form we cannot allow you to visit this site.
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------