Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

some scripts

  • Loading branch information...
commit 41a8d3d8dc1c81c86a2d5a677b48b9dd2ed8c668 1 parent 7d84498
ssadler authored
59 bin/httpreq
View
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+import sys, re, select, datetime
+from optparse import OptionParser
+
+default_user_agent = """Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.6pre) Gecko/20100614 Ubuntu/9.04 (jaunty) httpreq"""
+
+parser = OptionParser(usage = "%prog [options] url", version="0.1",
+ description="Http request header generator")
+parser.add_option('-m', '--method', dest='method', default='GET', help="method to use")
+parser.add_option('-i', '--ifmod', dest='ifmod', default=None, help="seconds since modified",
+ type='int')
+parser.add_option('-v', '--verbose', dest='verbose', action="count", help="print request to stderr")
+parser.add_option('-u', '--user-agent', dest="user_agent", default=default_user_agent)
+parser.add_option('-a', '--header', action='append', dest='headers')
+options, args = parser.parse_args()
+
+if len(args) != 1:
+ parser.error('missing url')
+
+def parse_uri(uri):
+ """Splits a URI into it's components."""
+ re_uri = re.compile('([a-z]+://)?(?:(.*?):(.*?)@)?([^:/]+)(?::(\d+))?(.*)$')
+ match = re_uri.match(uri)
+ assert match, "Invalid URI: %s" % uri
+ fields = ('scheme', 'user', 'pass', 'host', 'port', 'path')
+ return dict(zip(fields, match.groups()))
+
+parsed = parse_uri(args[0].strip())
+assert parsed['scheme'] in (None, 'http://'), "invalid scheme: " + parsed['scheme']
+
+headers = ['%s %s %s' % (options.method, parsed['path'] or '/', 'HTTP/1.1')]
+
+host = parsed['host']
+if parsed['port'] not in (None, '80'):
+ host += ':' + parsed['port']
+headers.append('Host: ' + host)
+
+if options.ifmod != None:
+ cachedate = datetime.datetime.now() - datetime.timedelta(seconds=options.ifmod)
+ cachedate = cachedate.strftime('%a, %d %b %Y %H:%M:%S')
+ headers.append('If-Modified-Since: ' + cachedate)
+
+headers.append("User-Agent: " + options.user_agent)
+headers.append("Connection: Close")
+if options.headers:
+ headers += options.headers
+
+post_data = ''
+if options.method == 'POST':
+ post_data = sys.stdin.read()
+ headers.append('Content-Length: %s' % len(post_data))
+
+out = "\r\n".join(headers) + "\r\n\r\n" + post_data
+
+if options.verbose:
+ print >>sys.stderr, "\033[42m%s\033[1;m" % out
+
+sys.stdout.write(out)
50 bin/pyline
View
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import sys, os, re, getopt
+from functools import partial
+
+# parse options for module imports
+opts, args = getopt.getopt(sys.argv[1:], 'm:')
+opts = dict(opts)
+if '-m' in opts:
+ for imp in opts['-m'].split(','):
+ locals()[imp] = __import__(imp.strip())
+
+code_part = partial(compile, sys.argv[1], __file__);
+try:
+ mode = 'eval'
+ code = code_part(mode)
+except SyntaxError:
+ mode = 'exec'
+ code = code_part(mode)
+
+shortcuts = {
+ 'run': lambda line, cmd: os.system(cmd.replace('%s', line)),
+ 's': lambda line, char, index=0: line.split(char, index+1)[index],
+}
+
+re_compiled = {}
+def match(pattern, data):
+ r = re_compiled.get(pattern)
+ if not r:
+ r = re_compiled[pattern] = re.compile(pattern)
+ m = r.match(data)
+ if m:
+ return m.groups()
+ return None
+
+i = 1
+try:
+ for line in sys.stdin:
+ l = line = line[:-1]
+ words = line.split()
+ for shortcut_name, func in shortcuts.items(): locals()[shortcut_name] = partial(func, line)
+ try:
+ out = eval(code, globals(), locals())
+ if mode == 'eval' and out:
+ print out
+ i += 1
+ except IndexError:
+ pass
+except KeyboardInterrupt:
+ sys.exit(1)
25 bin/pylines
View
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+
+import sys, os
+from functools import partial
+
+code_part = partial(compile, sys.argv[1], __file__);
+
+try:
+ mode = 'eval'
+ code = code_part(mode)
+except SyntaxError:
+ mode = 'exec'
+ code = code_part(mode)
+
+try:
+ lines = sys.stdin.readlines()
+ lines = map(str.strip, lines)
+ out = eval(code, globals(), locals())
+ if hasattr(out, '__call__'):
+ out = out(lines)
+ if mode == 'eval' and out:
+ print out
+except KeyboardInterrupt:
+ sys.exit(1)
+
12 bin/socks
View
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+LISTENADDR="0.0.0.0:$1"
+shift
+
+export AUTOSSH_DEBUG=1
+export AUTOSSH_LOGLEVEL=7
+
+echo "socks starting at $LISTENADDR"
+
+autossh -M 0 -ND $LISTENADDR -o ServerAliveInterval=100 -o ServerAliveCountMax=2 -o ConnectTimeout=5 -o Compression=yes -o TCPKeepAlive=yes $@
+
6 bin/tun
View
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+A=$1
+shift
+
+autossh -M 0 -L $A -N $*
40 bin/webshare
View
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+import BaseHTTPServer, SocketServer
+from SimpleHTTPServer import SimpleHTTPRequestHandler
+import socket
+import fcntl
+import struct
+import sys
+
+class HTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
+ def __init__(self, server_address, RequestHandlerClass=None):
+ BaseHTTPServer.HTTPServer.__init__(self, server_address, RequestHandlerClass)
+
+def get_ip_address(ifname):
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ return socket.inet_ntoa(fcntl.ioctl(
+ s.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', ifname[:15])
+ )[20:24])
+
+ifname = 'eth0'
+#ip = get_ip_address(ifname)
+ip = '0.0.0.0'
+
+
+
+if sys.argv[1:]:
+ port = int(sys.argv[1])
+else:
+ port = 8000
+server_address = (ip,port)
+
+HTTPServer.protocol_version = 'HTTP/1.0'
+httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
+
+sa = httpd.socket.getsockname()
+print "Serving HTTP on", sa[0], "port", sa[1], "..."
+httpd.serve_forever()
+
Please sign in to comment.
Something went wrong with that request. Please try again.