File: eepsitefetcher.py

package info (click to toggle)
python-txi2p-tahoe 0.3.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 448 kB
  • sloc: python: 3,757; makefile: 163; sh: 3
file content (37 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import print_function
from sys import stdout
from twisted.internet import reactor
from twisted.internet.endpoints import clientFromString
from twisted.internet.protocol import ClientFactory, Protocol


class Eepsite(Protocol):
    def connectionMade(self):
        print('Connection made, sending eepsite request')
        self.transport.write(b'GET / HTTP/1.1\r\n\r\n')

    def dataReceived(self, data):
        stdout.write(data)

    def connectionLost(self, reason):
        print('Lost connection. Reason:', reason)
        reactor.stop()


class EepsiteFactory(ClientFactory):
    protocol = Eepsite


endpoint = clientFromString(reactor, 'i2p:stats.i2p:81')
d = endpoint.connect(EepsiteFactory())
def printProto(proto):
    print('My address:')
    print(proto.transport.getHost())
    print('Eepsite address:')
    print(proto.transport.getPeer())
def printErr(err):
    print(err)
    reactor.stop()
d.addCallbacks(printProto, printErr)

reactor.run()