Skip to content

Instantly share code, notes, and snippets.

Avatar
😸
use code::latest ;

GAURAV gauravssnl

😸
use code::latest ;
View GitHub Profile
@gauravssnl
gauravssnl / ping.py
Created Dec 14, 2016 — forked from pklaus/ping.py
A pure python ping implementation using raw socket.
View ping.py
#!/usr/bin/env python2
"""
Other Repositories of python-ping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* https://github.com/l4m3rx/python-ping supports Python2 and Python3
* https://bitbucket.org/delroth/python-ping
View ping.py
import time
import random
import struct
import select
import socket
def chk(data):
x = sum(x << 8 if i % 2 else x for i, x in enumerate(data)) & 0xFFFFFFFF
x = (x >> 16) + (x & 0xFFFF)
@gauravssnl
gauravssnl / nope.py
Created Dec 14, 2016
This imports something from the parent dir of the script file in a very nasty way.
View nope.py
# This is some butt ugly fuckery that basically chdirs to the
# directory that is parent to this source file, imports the
# test subject from the main script, then de-imports (not really
# cause Python doesn't support that) the stuff that it needed to
# do that as not to pollute the name space and cause tests to
# possibly fail because of that.
#
# In order for this to work it's imperative that you:
# - Have the main script on the parent directory to the one
# this script file is in.
@gauravssnl
gauravssnl / keysmith.py
Created Dec 14, 2016
🔑 Generates and validates random url-safe user-readable strings.
View keysmith.py
from os import urandom
from base64 import b64encode
from string import ascii_letters, digits
def randkey(size=6, altchars=b'+.', ambiguous=b'IlO9GUS'):
key = ''
while len(key) < size:
chunk = b64encode(urandom(size*2), altchars)
key += str(bytes([c for c in chunk if c not in ambiguous]), encoding='utf-8')
@gauravssnl
gauravssnl / fetch-conference.py
Created Dec 14, 2016 — forked from pklaus/fetch-conference.py
Downloading Slides from Indico
View fetch-conference.py
#!/usr/bin/env python
"""
Tool to download conference information from Indico
"""
import json, argparse, sys, re, logging, os, importlib
logger = logging.getLogger(__name__)
logging.basicConfig(format='%(levelname)s: %(message)s')
@gauravssnl
gauravssnl / convert-pickle-version.py
Created Dec 14, 2016 — forked from pklaus/convert-pickle-version.py
A command line tool to convert between pickle protocol versions
View convert-pickle-version.py
#!/usr/bin/env python
import pickle
import argparse
import sys
def main():
parser = argparse.ArgumentParser(description='Convert between pickle protocol versions.')
parser.add_argument('input_file')
parser.add_argument('output_file')
@gauravssnl
gauravssnl / wifiscan.py
Created Dec 14, 2016 — forked from pklaus/wifiscan.py
Run `iw wlan0 scan` and interpret output with Python
View wifiscan.py
#!/usr/bin/env python
# originally from johnl found at
# http://ubuntuforums.org/showthread.php?t=1604981&p=10024295#post10024295
import subprocess
import re
class line_matcher:
def __init__(self, regexp, handler):
View Simple DNS server (UDP and TCP) in Python using dnslib.py
# coding=utf-8
"""
LICENSE http://www.apache.org/licenses/LICENSE-2.0
"""
import datetime
import sys
import time
import threading
import traceback
import SocketServer
@gauravssnl
gauravssnl / ddns.py
Created Dec 14, 2016 — forked from pklaus/ddns.py
A script to update the A and AAAA RRs of HOSTNAME on a DNS server according to your current external IP address using nsupdate / TSIG. This script is tested to run on Mac OS X (10.8-10.9) but you should be able to get it up and running in almost no time on any Unix or Linux system that ships nsupdate. I use this script to update my own DDNS serv…
View ddns.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Written on 2013-02-04 by Philipp Klaus <philipp.l.klaus →AT→ web.de>.
Check <https://gist.github.com/4707775> for newer versions.
Uses dnspython: install with `pip install dnspython3`
"""
@gauravssnl
gauravssnl / dnsupdate.py
Created Dec 14, 2016 — forked from pklaus/dnsupdate.py
dnsupdate is meant to replace nsupdate, the standard DDNS update tool created by BIND authors ISC. While nsupdate does the job it is awkward to wrap in scripts and its usage in general is just not very intuitive. dnsupdate is meant to work well from the command line or from scripts and easy to use. It also does some nice things like automaticall…
View dnsupdate.py
#!/usr/bin/env python2.7
# Matt's DNS management tool
# Manage DNS using DDNS features
#
# See http://planetfoo.org/blog/archive/2012/01/24/a-better-nsupdate/
#
# Usage: dnsupdate -s server -k key -t ttl add _minecraft._tcp.mc.example.com SRV 0 0 25566 mc.example.com.
# -h HELP!
# -s the server
# -k the key