Skip to content

Instantly share code, notes, and snippets.

@aconz2
aconz2 / noworks.py
Last active May 18, 2023 12:31
asyncio ssl get peercert
# WARNING: this doesn't work properly
import asyncio
import ssl
import socket
# included logging to try to figure out why this wasn't working...
import logging
logging.basicConfig()
logging.getLogger('asyncio').setLevel(logging.DEBUG)
@garyconstable
garyconstable / scan.py
Last active September 6, 2022 21:32
Python port scanner - TCP SYN (half open) scanning
from scapy.all import sr, IP, TCP
import argparse
import time
class scanner():
def __init__(self, host_start, host_end):
from random import randrange
from twisted.internet.defer import DeferredQueue
from twisted.internet.task import deferLater, cooperate
from twisted.internet import reactor
def async(n):
print 'Starting job', n
d = deferLater(reactor, n, lambda: None)
@delimitry
delimitry / compiled_file_python_version.py
Last active May 21, 2025 19:23
Get the version of Python by which the file was compiled
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A script to get the version of Python by which the file was compiled
"""
from __future__ import print_function
import binascii
import os
def contains(subseq, inseq):
return any(inseq[pos:pos + len(subseq)] == subseq for pos in range(0, len(inseq) - len(subseq) + 1))
class TestContainsForString(unittest.TestCase):
def test_smoketest(self):
self.assertTrue(contains('abc', 'abc cde fgi'))
def testcontains_middle_seq(self):
@sh1n0b1
sh1n0b1 / ssltest.py
Created April 8, 2014 07:53
Python Heartbleed (CVE-2014-0160) Proof of Concept
#!/usr/bin/python
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
@gpduck
gpduck / Start-Webserver.ps1
Last active January 12, 2017 12:59
PowerShell Web Server Framework
<#
.SYNOPSIS
Start a web server that will route requests to a series of script blocks as defined by the -Routes parameter.
.DESCRIPTION
Starts a single-threaded web server and responds to requests by executing the script blocks that are
defined as routes on the command line.
.NOTES
Copyright 2013 Chris Duck
@metachris
metachris / tcpclient.py
Last active July 2, 2020 07:46
Tornado TCP Client (Simple)
import errno
import socket
from threading import Thread
from tornado import ioloop
class IOLoopThread(Thread):
def __init__(self):
Thread.__init__(self)
self.running = True
@niccokunzmann
niccokunzmann / RemoteException.py
Last active March 24, 2024 16:02
See the traceback of the error occurring from the other process with multiprocessing.
import sys
import traceback
import StringIO
from copy_reg import dispatch_table, pickle
def exc_info(hide_calls = 0):
'''as sys.exc_info() but returns a remote exception object'''
ErrorType, thrownError, traceback = sys.exc_info()
for i in range(hide_calls):
@willurd
willurd / web-servers.md
Last active October 24, 2025 16:17
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000