#!/usr/bin/python2.5 import socket import sys import getopt from threading import Thread import bson import time SEND_PORT=8124 DEBUG = False def debugOut(str): if DEBUG: print str ''' takes a dictionary and sends the BSON representation to SEND_IP:SEND_PORT ''' def sendCNC(dict, sock): c = bson.dumps(dict) b = bson.loads(c) debugOut('\nsending to %s:%s' % (sys.argv[2], SEND_PORT)) debugOut('packet: %s' % b) sock.sendto(c,(sys.argv[2], SEND_PORT)) # Send one request packet class CNCSenderThread(Thread): def __init__(self, port = SEND_PORT): Thread.__init__(self, name='Sender') if(len(sys.argv) > 2): self.ip = sys.argv[2] self.port = port def run(self): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # send traceroute packet sendCNC( { # "response_ip": "127.0.0.1", # "response_port": 8123, "id": sys.argv[1], "cmd":"traceroute", "args":{"dest": sys.argv[3]} }, sock) def main(): if(len(sys.argv) < 4): print "Usage: "+sys.argv[0]+" " exit(1) sender = CNCSenderThread() sender.start() if __name__ == '__main__': main()