Skip to content

Instantly share code, notes, and snippets.

View joneskoo's full-sized avatar

Joonas Kuorilehto joneskoo

View GitHub Profile
@joneskoo
joneskoo / gist:812505
Created February 5, 2011 15:05
ident-lookup.py
#!/usr/bin/env python
# Ident lookup for incoming connections
# RFC 1413 - Identification Protocol
import socket
def lookup_ident(host, server_port, client_port):
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((host, 113))
@joneskoo
joneskoo / gist:829065
Created February 16, 2011 09:01
Quick and dirty PCAP parser
#include <pcap.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#define IP_SRC_OFFSET 34-8
#define IP_DST_OFFSET 38-8
void dump(char *name);
@joneskoo
joneskoo / reverse_validator.py
Created February 16, 2011 11:03
Validates that each IPv4/IPv6 address has a valid reverse DNS (including forward DNS)
#!/usr/bin/env python
import sys
from os.path import basename
from dns import resolver, reversename
import socket
def get_single_reverse(ip):
rname = reversename.from_address(ip)
try:
responses = resolver.query(rname, "PTR")
@joneskoo
joneskoo / urllib-example.py
Created March 6, 2011 12:00
urllib example in python3
#!/usr/bin/env python3.1
import urllib.request
opener = urllib.request.FancyURLopener()
f = opener.open('https://localhost/url')
print(f.read())
@joneskoo
joneskoo / batteryinfo.py
Created August 21, 2011 07:29
Read battery information from System Profiler (OS X)
#!/usr/bin/env python3
from tempfile import NamedTemporaryFile
from subprocess import call
import plistlib
with NamedTemporaryFile() as f:
call(['system_profiler', '-xml', 'SPPowerDataType'], stdout=f)
f.seek(0)
p = plistlib.readPlist(f)
@joneskoo
joneskoo / gist:1218504
Created September 15, 2011 04:01
Sikteeri list members by month
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/1218504
"""
generate_test_data.py
Copyright (c) 2010-2011 Kapsi Internet-käyttäjät ry. All rights reserved.
"""
import sys
@joneskoo
joneskoo / udpsender.py
Created October 21, 2011 22:20
UDP sender
#!/usr/bin/env python
import socket
import sys
PREFIX = "PREFIX:"
HOST = '127.0.0.1'
PORT = 5555
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@joneskoo
joneskoo / ssh-knownhosts-cleanup.py
Last active April 3, 2023 00:42
SSH known hosts cleanup script. Combines same fingerprints to one line.
#!/usr/bin/env python3
# encoding: utf-8
# By Joonas Kuorilehto 2011, MIT license
#
# The script combines .ssh/known_hosts so that each fingerprint is only
# listed once.
import re
import sys
import os
@joneskoo
joneskoo / pyspammer.py
Created October 25, 2011 05:43
Python spammer with unicode support
#!/usr/bin/env python3
# encoding: utf-8
import smtplib
from email.message import Message
from email.header import Header
from email.utils import formataddr
SMTP_SERVER = 'mail.suomi.net'
FROM_NAME = 'Example Sender'
@joneskoo
joneskoo / postita.py
Created October 28, 2011 05:33
Postita API example with requests
#!/usr/bin/env python
# coding: utf-8
import requests
import json
import base64
URL_ROOT = "https://postita.fi/api/"
PDF_PATH = 'muistutusviesti.pdf'
USER = None