Exemple #1
0
def load():
	queue=Queue()
	hostfile_line=open(sys.argv[2],'r').readlines()
	source=sys.argv[3]
	destdir=sys.argv[4]
	for hostfile in hostfile_line:
		eachline=hostfile.split()
		queue.put(eachline)
		eachline=Process(target=TRANS,args=(queue.get(),source,destdir))
		eachline.start()
	eachline.join()
Exemple #2
0
def exe():
	queue=Queue()
	hostfile_line=open(sys.argv[2],'r').readlines()
	command_file=open(sys.argv[3],'r').readlines()
	for command_line in command_file:
		command_list=command_line.split('\n')
		command=''.join(command_list)
		for hostfile in hostfile_line:
			eachline=hostfile.split()
			queue.put(eachline)
			eachline=Process(target=SSH,args=(queue.get(),str(command)))
			eachline.start()
	eachline.join()
Exemple #3
0
	def cmdrun(self, cmd):
		comScanCmd = cmd
		queue = Queue()
		scanProc = Process(
			target=self.newProcExecuteCmd, args=[queue, comScanCmd])
		scanProc.start()
		# 等待5秒
		scanProc.join(10)
		try:
			scanResult = queue.get(timeout=5)
		except Exception as e:
			print "get cmd result error"
			scanResult = -1
		scanProc.terminate()
		return scanResult
Exemple #4
0
 def cmdrun(self, cmd):
     try:
         comScanCmd = cmd
         queue = Queue()
         scanProc = Process(target=self.newProcExecuteCmd,
                            args=[queue, comScanCmd])
         scanProc.start()
         scanProc.join(5)
         try:
             scanResult = queue.get(timeout=30)
             #print scanResult
         except Exception, e:
             print e
             print "get cmd result error: %s " % str(e)
             scanResult = -1
         scanProc.terminate()
         return scanResult
python_pingSweep_threading.py, but relies on processing instead of threading.
'''

# Import my own modules here
import python_myFunctions as myFunctions
mf = myFunctions.CreateObject()

# All other required modules here
from processing import Process, Queue, Pool
import time
import subprocess
from IPy import IP  #sudo easy_install IPy
import sys

# Declarations here
queue = Queue()
# Create an instance of an IP object.  If no size specification is given a size of 1 address (/32 for IPv4 and /128 for IPv6) is assumed.
#ipAddresses = IP("10.0.1.0/24") #generates 10.0.1.0 -> 10.0.1.255
ipAddresses = ["172.20.43.175", "194.42.7.189", "194.42.7.57", "127.0.0.1"]
nProcesses = 2


def f(iProcess, queue):
    # Create an infinite loop!
    while True:
        # Place a conditional statement for exiting the loop
        if queue.empty():
            mf.Cout("Queue for Process #%s is empty. Exiting python shell." %
                    (iProcess))
            #print __doc__
            sys.exit(1)
Exemple #6
0
#-*- coding: utf-8 -*-
from processing import Process, Queue
import time


def f(q):
    x = q.get()
    print 'Process Number %s, sleeps for %s seconds' % (x, x)
    time.sleep(x)
    print 'Process Number %s finished' % x


q = Queue()

for i in range(10):
    q.put(i)
    p = Process(target=f, args=[q])
    p.start()

print 'main process joins on queue'
p.join()
'''
为什么
main process joins on queue
出现的位置不固定,
难道是因为给进程分配资源需要时间而导致的么???
'''
print 'main process finished'
Exemple #7
0
def f(q):
    x = q.get()
    print "Process number %s, sleeps for %s seconds" %(x, x)
    time.sleep(x)
    print "Process number %s finished"  % x
    q = Queue()
#!/usr/bin/env python3
#snmp_discover.py

from processing import Process, Queue, Pool
import time
import subprocess
import sys
from snmp import Snmp

q = Queue()
oq = Queue()
#ips = IP("10.0.1.0/24")
ips = ["10.0.28.11", "10.0.28.10", "10.0.28.9", "10.0.29.100", "10.0.28.7"]
num_workers = 10


class HostRecord():
    """Record for Hosts"""
    def __init__(self, ip=None, mac=None, snmp_response=None):
        self.ip = ip
        self.mac = mac
        self.snmp_response = snmp_response

    def __repr__(self):
        return f"[Host Record({self.ip},{self.mac},{self.snmp_response})]"


def f(i, q, oq):
    while True:
        time.sleep(.1)
        if q.empty():
Exemple #9
0
            if len(message["match"]) > 0 or message.has_key("host") or message.has_key("smtpresp"):
                sendmsg(channel, json.dumps(message))
        except Exception, e:
            print e

def worker(inp, outp):
    for arg in iter(inp.get, 'STOP'):
        try:
            rez = dopcap(arg)
            os.unlink(arg)
        except Exception, e:
            print e
        print "Done: %s" % arg


task_queue = Queue()
done_queue = Queue()

for i in range(PROCS):
    Process(target=worker, args=(task_queue, done_queue)).start()


class CloseEvent(ProcessEvent):
    def process_IN_CLOSE_WRITE(self, event):
        task_queue.put("%s" %  os.path.join(event.path, event.name))
        print "Received: %s" % os.path.join(event.path, event.name)

wm = WatchManager()

notifier = Notifier(wm, CloseEvent())
wdd = wm.add_watch('/data2', pyinotify.IN_CLOSE_WRITE, rec=True)
Exemple #10
0
from processing import Process, Queue, Pool
import time
import subprocess
from IPy import IP
import sys

q = Queue()
ips = IP("10.0.1.0/24")


def f(i, q):
    while True:
        if q.empty():
            sys.exit()
        print "Process Number: %s" % i
        ip = q.get()
        ret = subprocess.call("ping -c 1 %s" % ip,
                              shell=True,
                              stdout=open('/dev/null', 'w'),
                              stderr=subprocess.STDOUT)
        if ret == 0:
            print "%s: is alive" % ip
        else:
            print "Process Number: %s didn't find a response for %s" % (i, ip)


for ip in ips:
    q.put(ip)
#q.put("192.168.1.1")

for i in range(50):
Exemple #11
0
def algo(request, algo):
    text = ""
    type = ""
    algo_object = get_object_or_404(Algo, shortTitle=algo)
    manual = get_object_or_404(ManPage, algo=algo_object)
    
    embedFormDict = { 'cpt' : CPTEmbedForm,
                   'f5' : F5EmbedForm,
                   'lsb' : LsbEmbedForm,
                   'gifshuffle' : GifShuffleEmbedForm,
                   'bs' : BattlestegEmbedForm, }
    
    extractFormDict = { 'cpt' : CPTExtractForm,
                   'f5' : F5ExtractForm,
                   'lsb' : LsbExtractForm,
                   'gifshuffle' : GifShuffleExtractForm,
                   'bs' : BattlestegExtractForm, }
    typeDict = { 'cpt' : "png",
               'f5' : "jpeg",
               'lsb' : "png",
               'gifshuffle' : "gif",
               'bs' : "png", }
    
    if request.method == 'POST':
        
        q = Queue()
        # embedding
        if "submit1" in request.POST:
            
            algoDict = { 'cpt' : cptEmbed,
                           'f5' : f5Embed,
                           'lsb' : lsbEmbed,
                           'gifshuffle' : gifShuffleEmbed,
                           'bs' : bsEmbed, }
            
            embedForm = embedFormDict[algo](request.POST, request.FILES)
            extractForm = extractFormDict[algo]()
            type = typeDict[algo]
            p = Process(target=algoDict[algo], args=(q, ))

            # fork process to embed
            if embedForm.is_valid():
                p.start()
                q.put([request.POST, request.FILES['file'].temporary_file_path()])
                os.system("sleep 1")
                try:
                    retval = q.get(True, 10)
                except Q.Empty:
                    retval = -2
                p.join()
                if retval == -1:
                    text += "%s-Datei nicht gefunden oder fehlerhaft."%(type)
                elif retval == -2:
                    text += "Fehler beim Einbetten. Anderes Bild oder andere Parameter versuchen."
                else:
                    return createResponse(retval, type)
        # extracting        
        elif "submit2" in request.POST:
             
            algoDict = { 'cpt' : cptExtract,
                           'f5' : f5Extract,
                           'lsb' : lsbExtract,
                           'gifshuffle' : gifShuffleExtract,
                           'bs' : bsExtract, }

            embedForm = embedFormDict[algo]()
            extractForm = extractFormDict[algo](request.POST, request.FILES)
            type = typeDict[algo]
            p = Process(target=algoDict[algo], args=(q, ))
            
            # fork process to extract
            if extractForm.is_valid():
                p.start()
                q.put([request.POST, request.FILES['file'].temporary_file_path()])
                try:
                    retval = q.get(True, 10)
                except Q.Empty:
                    retval = -2
                p.join()
                if retval == -1:
                    text += "%s-Datei nicht gefunden oder fehlerhaft."%(type)
                elif retval == -2:
                    text += "Fehler beim Ausbetten. Anderes Bild oder andere Parameter versuchen."
                else:
                    #print retval
                    text += retval
    # empty form
    else:
        embedForm = embedFormDict[algo]()
        extractForm = extractFormDict[algo]()
    # render
    return render_to_response("stego_algo.html", {'algo' : algo_object,
                                            'embedForm' : embedForm, 
                                            'extractForm' : extractForm,
                                            'text' : text,
                                            'algo_type' : 'Staganographie',
                                            'manual' : manual,}) 
Exemple #12
0
#!/usr/bin/env python
from processing import Process, Queue
import time

def f(q):
    x = q.get()
    print "Process number %s, sleeps for %s seconds" % (x,x)
    time.sleep(x)
    print "Process number %s finished" % x
q = Queue()

for i in range(10):
    q.put(i)
    i = Process(target=f, args=[q])
    i.start()

print "main process joins on queue"
i.join()
print "Main Program finished"
Exemple #13
0
         #datetime(2004, 8,  2, 0, 0), 
         #datetime(2004, 8,  3, 0, 0), 
         #datetime(2004, 8,  4, 0, 0), 
         #datetime(2004, 8,  5, 0, 0), 
         #datetime(2004, 8,  6, 0, 0),
         
         #datetime(2004, 8,  9, 0, 0), 
         #datetime(2004, 8, 10, 0, 0), 
         #datetime(2004, 8, 11, 0, 0), 
         #datetime(2004, 8, 12, 0, 0), 
         #datetime(2004, 8, 13, 0, 0),
     ]
         
 # create Queues
 queue = BufferedQueue()
 result = Queue()
 
 p1 = Process(target=process_func, args=[queue, result])
 p2 = Process(target=process_func, args=[queue, result])
 p1.setStoppable(True); p2.setStoppable(True)
 p1.start(); p2.start()
 
 #strategy_args = random_strategies_generator_2(periods=(1,2,3,4,5), 
 #                                              strats_per_period=24)
 strategy_args = [
     (('long_tops', 4, 'low', 'HH', 6, 7), ('short_tops', 4, 'high', 'LL', 6, 7))
 ]
 
 for (s1, s2) in strategy_args:
     print s1, s2
 
mf = myFunctions.CreateObject()

# All other required modules here
from processing import Process, Queue
import time

def f(queue):
    x = queue.get()
    mf.Cout("Process number %s, sleeps for %s seconds" % (x,x))
    time.sleep(x)
    mf.Cout("Process number %s finished" % (x))
    
if __name__ == "__main__":
    mf.StopWatchStart()
    # Create a queue object 
    queue = Queue()
    # Create 10 processes
    for i in range(10):
        # Put an item into the queue. 10 queues in total
        queue.put(i)
        # Declare the process
        mf.Cout("Creating process #%s" % (i))
        i = Process(target = f, args=[queue]) #for a Thread: threading.Thread(target = f, args=(queue)) => Similar structure
        # Start the process
        i.start()

    mf.Cout("Main process joins on queue")
    # Block process until all items in the Queue have been gotten and processed
    i.join()
    mf.Cout("Main program finished")
Exemple #15
0
#!/usr/bin/env python
from processing import Process, Queue, Pool
import time
import subprocess
from IPy import IP
import sys

q = Queue()
ping_out_queue = Queue()
snmp_out_queue = Queue()
ips = IP("10.0.1.0/24")
num_ping_workers = 10
num_snmp_workers = 10

def ping(i,q,out=out_queue):
    while True:
        if q.empty():
            sys.exit()
        #print "Process Number: %s" % i
        ip = q.get()
        ret = subprocess.call("ping -c 1 %s" % ip,
                        shell=True,
                        stdout=open('/dev/null', 'w'),
                        stderr=subprocess.STDOUT)
        if ret == 0:
            print "%s: is alive" % ip
            out.put(ip)
        else:
            pass

def snmp(i,q=ping_out_queue,out=snmp_out_queue)
Exemple #16
0
#!/usr/bin/env python
from processing import Process, Queue, Pool
import time
import subprocess
import sys
from snmp import Snmp
import pdb

q = Queue()
oq = Queue()
#ips = ["172.30.44.1","172.30.44.46","172.30.44.47"]
ips = ["192.168.1.1", "192.168.1.67"]
num_workers = 10


class HostRecord(object):
    """ Record for hosts """
    def __init__(self, ip=None, mac=None, snmp_response=None):
        self.ip = ip
        self.mac = mac
        self.snmp_response = snmp_response

    def __repr__(self):
        return "[Host Record('%s','%s','%s')]" % (self.ip, self.mac,
                                                  self.snmp_response)

    def f(i, q, oq):
        while True:
            time.sleep(.1)
            if q.empty():
                sys.exit()
Exemple #17
0
#!/usr/bin/env python
from processing import Process, Queue, Pool
import time
import subprocess
from IPy import IP
import sys
from snmp import Snmp

q = Queue()
oq = Queue()
#ips = IP("10.0.1.0/24")
ips = ["192.19.101.250", "192.19.101.251", "192.19.101.252","192.19.101.253",
"192.168.1.1"]
num_workers = 10

class HostRecord(object):
    """Record for Hosts"""
    def __init__(self, ip=None, mac=None, snmp_response=None):
        self.ip = ip
        self.mac = mac
        self.snmp_response = snmp_response
    def __repr__(self):
        return "[Host Record('%s','%s','%s')]" % (self.ip,
                                            self.mac,
                                            self.snmp_response)

def f(i,q,oq):
    while True:
        time.sleep(.1)
        if q.empty():
            sys.exit()
Exemple #18
0
from processing import Process, Queue, Pool
import time
import subprocess
from IPy import IP
import sys

q = Queue()
ips = IP("10.0.1.0/24")

def f(i,q):
	while True:
		if q.empty():
			sys.exit()
		print "Process Number: %s" %i
		ip = q.get()
		ret = subprocess.call("ping -c 1 %s"%ip, shell=True,stdout=open('/dev/null','w'),stderr = subprocess.STDOUT)
		if ret == 0 :
			print "%s: is alive"%ip
		else:
			print "Process Number: %s didn't find a response for %s"%(i,ip)

for ip in ips:
	q.put(ip)
#q.put("192.168.1.1")

for i in range(50):
	p = Process(target=f, args=[i,q])
	p.start()

print "main process joins on queue"
p.join()
Exemple #19
0
#!/usr/bin/env python

from processing import Process, Queue, Pool
import time
import subprocess
import sys
from snmp import Snmp

q = Queue()
oq = Queue()
#ips = IP("192.168.0.0/24")
ips = ["192.19.101.250", "192.19.101.251", "192.19.101.252","192.19.101.253","192.168.1.1"]
num_workers = 10

class HostRecord(object):
    """Record for Hosts"""
    def __init__(self, ip=None, mac=None, snmp_response=None):
        self.ip = ip
        self.mac = mac
        self.snmp_response = snmp_response
    def __repr__(self):
        return "[Host Record('%s','%s','%s')]" % (self.ip,self.mac,self.snmp_response)

def f(i,q,oq):
    while True:
        time.sleep(.1)
        if q.empty():
             sys.exit()
             print "Process Number: %s Exit" % i
        ip = q.get()
        print "Process Number: %s" % i
Exemple #20
0
def test():
    NUMBER_OF_PROCESSES = 4
    TASKS1 = [(mul, (i, 7)) for i in range(20)]
    TASKS2 = [(plus, (i, 8)) for i in range(10)]

    # Create queues
    task_queue = Queue()
    done_queue = Queue()

    # Submit tasks
    task_queue.putMany(TASKS1)

    # Start worker processes
    for i in range(NUMBER_OF_PROCESSES):
        Process(target=worker, args=(task_queue, done_queue)).start()

    # Get and print results
    print 'Unordered results:'
    for i in range(len(TASKS1)):
        print '\t', done_queue.get()

    # Add more tasks using `put()` instead of `putMany()`
    for task in TASKS2:
        task_queue.put(task)

    # Get and print some more results
    for i in range(len(TASKS2)):
        print '\t', done_queue.get()

    # Tell child processes to stop
    for i in range(NUMBER_OF_PROCESSES):
        task_queue.put('STOP')