Posts

Showing posts from January, 2010

2 starting comments for a python script

Every python script should start with 2 lines in comment. These will define important aspects of your script's behaviour. #!/usr/bin/python # -*- coding: utf-8 -*- The shebang on the first line makes the script executable as a shell script (= you can execute the script without having to type "python" in front of its filename). The next line sets the default character set for your script. All string literals inside your script will be interpreted according to this character set. Since we are using utf-8, we can write string literals with unicode characters inside of them.

python port sniffer with pcapy and impacket

The code below will sniff all network traffic (use a filter to limit the sniffer to only certain packets) during 1000 milliseconds and print some info about it. It requires 2 python modules: pcapy for capturing the packets impacket for analyzing the packet content Note that this sample uses pcapy's dispatch() method and relies on its ability to return automatically after a timeout expires. This functionality is not available on all platforms (e.g. not on linux). import os, logging, socket import pcapy, impacket, impacket.ImpactDecoder ETHERNET_MAX_FRAME_SIZE = 1518 PROMISC_MODE = 0 class Packet(object): def __init__(self, bytes, sniffed_bytes, timestamp, proto_id, src_ip, tgt_ip, src_port, tgt_port, msgs): """ @brief Initialize data. """ super(Packet, self).__init__() self.bytes = bytes self.sniffed_bytes = sniffed_bytes self.src_ip = src_ip self.tgt_ip = tgt_ip self.src_port = src_port self.tgt_port = tgt_port ...

Removing Auth menu from django admin

By default, when including 'django.contrib.auth' as part of your django project's INSTALLED_APPS , an "Auth" section will be added to the project's admin frontpage. Following code in urls.py will remove this section from the admin: from django.contrib.auth.models import User, Group from django.contrib import admin admin.autodiscover() # remove "Auth" menu's from admin admin.site.unregister(User) admin.site.unregister(Group)