Differences
This shows you the differences between two versions of the page.
| — | development:python:os_thread [2019/10/31 09:05] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Python: Thread, for loop, script arguments, regex and OS execute ====== | ||
| + | For loop 255 times, create a thread, execute a function and pass a system argument, execuring a system command and printing its output | ||
| + | <code python> | ||
| + | # | ||
| + | |||
| + | import threading | ||
| + | import time | ||
| + | import os | ||
| + | import sys | ||
| + | import re | ||
| + | |||
| + | def ppp(addr): | ||
| + | response = os.system(' | ||
| + | |||
| + | if len(sys.argv) == 2: | ||
| + | if str(sys.argv[1]).endswith(' | ||
| + | ipbase=str(sys.argv[1]) | ||
| + | else: | ||
| + | ipbase=str(sys.argv[1]) + ' | ||
| + | |||
| + | pattern = re.compile(" | ||
| + | if pattern.match(ipbase): | ||
| + | for addrs in range(1, | ||
| + | x = threading.Thread(target=ppp, | ||
| + | x.start() | ||
| + | else: | ||
| + | print(' | ||
| + | else: | ||
| + | print(' | ||
| + | </ | ||