Skip to content

Instantly share code, notes, and snippets.

@hahastudio
hahastudio / dns_resolve.py
Created September 29, 2012 10:50
dns_resolve
import os
import re
import socket
import struct
def dns_resolve(host, dnsserver):
assert isinstance(host, basestring) and isinstance(dnsserver, basestring)
index = os.urandom(2)
hoststr = ''.join(chr(len(x))+x for x in host.split('.'))
data = '%s\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00%s\x00\x00\x01\x00\x01' % (index, hoststr)
@hahastudio
hahastudio / pypcap.py
Created October 16, 2012 09:28
python pcap file analyse
from pcapy import open_offline
def filter_HTTPGET(packet):
if packet[0x33] == '\x06' and packet[0x52:0x56] == "GET ":#tcp and tcp[20:4] = 0x47455420
return True
return False
def get_source_IP(packet):
#return '.'.join(str(ord(i)) for i in packet[0x36:0x3A])
return tuple(ord(i) for i in packet[0x36:0x3A])
# -*- coding: utf-8 -*-
"""
legit.scm
~~~~~~~~~
This module provides the main interface to Git.
"""
import os
from socket import *
import os
import struct
ADDR = ('59.78.41.61',5006)#你的IP,端口随意
BUFSIZE = 1024
filename = 'sort-collection.py'#文件名,把这个文件跟要传的文件放一个目录里
FILEINFO_SIZE=struct.calcsize('128s32sI8s')
sendSock = socket(AF_INET,SOCK_STREAM)
@hahastudio
hahastudio / mandelbrot.py
Created November 19, 2012 10:29
A Mandelbrot-Shaped Python Script that generate a Mandelbrot Fractal
_ = (
255,
lambda
V ,B,c
:c and Y(V*V+B,B, c
-1)if(abs(V)<6)else
( 2+c-4*abs(V)**-0.4)/i
) ;v, x=1500,1000;C=range(v*x
);import struct;P=struct.pack;M,\
j ='<QIIHHHH',open('M.bmp','wb').write
import dpkt, socket
f = open('t.cap', 'rb')
pcap = dpkt.pcap.Reader(f)
c = 0
for ts, buf in pcap:
# make sure we are dealing with IP traffic
# ref: http://www.iana.org/assignments/ethernet-numbers
#!/usr/bin/env python
import dpkt, socket
f = open('t.cap', 'rb')
pcap = dpkt.pcap.Reader(f)
c = 0
ptr_c = 0
log = open('4-seg-ip-dns-filter','w')
@hahastudio
hahastudio / TextEdit.py
Created December 20, 2012 13:49
A TextEdit editor that sends editingFinished events when the text was changed and focus is lost.
from PyQt4 import QtCore, QtGui
class TextEdit(QtGui.QTextEdit):
"""
A TextEdit editor that sends editingFinished events
when the text was changed and focus is lost.
"""
editingFinished = QtCore.pyqtSignal()
receivedFocus = QtCore.pyqtSignal()
from PyQt4 import QtCore
import glob
import os
import time
def all_files(pattern, search_path, pathsep=os.pathsep):
for path in search_path.split(pathsep):
for match in glob.glob(os.path.join(path, pattern)):
yield match
@hahastudio
hahastudio / ESWN.py
Created March 5, 2013 04:30
东南西北
#coding:utf-8
from random import choice
paper = [{'E': "天才", 'S': "笨蛋", 'W': "猪八戒", 'N': "大师兄"}, {'E': "Hentai", 'S': "绅士", 'W': "高富帅", 'N': "矮穷挫"}]
command = raw_input("Please input Direction and count, like: W25\n>>> ")
direction = command[0]
count = choice([0, 1]) + int(command[1:])
print paper[count % 2][direction]