File: test.py

package info (click to toggle)
python-socksipychain 2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 164 kB
  • sloc: python: 940; makefile: 54; sh: 15
file content (29 lines) | stat: -rwxr-xr-x 766 bytes parent folder | download
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
#!/usr/bin/python
from __future__ import print_function
from six.moves.urllib.request import urlopen

import ftplib
import telnetlib

try:
    import urllib.request as urllib_request  # Python 3
except ImportError:
    import urllib2 as urllib_request  # Python 2

# Import SocksiPy
import sockschain as socks
def DEBUG(msg): print(msg)
socks.DEBUG = DEBUG

# Set the proxy information
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 9050)

# Route an HTTP request through the SOCKS proxy 
socks.wrapmodule(urllib_request)
print('\n%s\n' % urlopen('http://bot.whatismyipaddress.com/').read())

# Route a telnet connection through the SOCKS proxy
socks.wrapmodule(telnetlib)
tn = telnetlib.Telnet('india.colorado.edu', 13)
print(tn.read_all())
tn.close()