def __init__(self, stdin, stdout, stderr, environ, multithread=True,
multiprocess=False):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
self.base_env = environ
self.wsgi_multithread = multithread
self.wsgi_multiprocess = multiprocess
python类__init__()的实例源码
def __init__(self, *args, **kwargs):
from google.appengine._internal.django.conf import settings
self.admin_media_prefix = settings.ADMIN_MEDIA_PREFIX
# We set self.path to avoid crashes in log_message() on unsupported
# requests (like "OPTIONS").
self.path = ''
self.style = color_style()
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
def __init__(self, application, media_dir=None):
from google.appengine._internal.django.conf import settings
self.application = application
if not media_dir:
import django
self.media_dir = os.path.join(django.__path__[0], 'contrib', 'admin', 'media')
else:
self.media_dir = media_dir
self.media_url = settings.ADMIN_MEDIA_PREFIX
def __init__(self, callback, handlerClass, port = 8881, address='0.0.0.0'):
threading.Thread.__init__(self)
self._stop = False
self._port = port
self._addr = address
self._handlerClass = handlerClass
self._handlerArgs = callback;
def handler(*args):
return self._handlerClass(self._handlerArgs, *args)
self._httpd = HTTPServer((self._addr, self._port), handler)
def __init__(self, callback, *args):
self._callback = callback
BaseHTTPRequestHandler.__init__(self, *args)
def __init__(self, interface, target, gateway):
print banner
print
self.interface = interface
print "[+] Interface: {}".format(self.interface)
def nic_ip(interface):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,
struct.pack('256s', interface[:15])
)[20:24])
except IOError:
print "[!] Select a valid network interface, exiting ..."
exit(0)
def nic_mac(interface):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', interface[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
self.hostIP = nic_ip(self.interface)
print "[+] This host IP Address: {}".format(self.hostIP)
self.hostMAC = nic_mac(self.interface)
print "[+] This host MAC Address: {}".format(self.hostMAC)
def resolve_mac(ip):
try:
conf.verb = 0
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op="who-has", pdst=ip), timeout=2)
for snd, rcv in ans:
return str(rcv[Ether].src)
except socket.gaierror:
print "[!] Select a valid IP Address as target/gateway, exiting ..."
exit(0)
self.targetIP = target
print "[+] Target IP Address: {}".format(self.targetIP)
self.targetMAC = resolve_mac(self.targetIP)
print "[+] Target MAC Address: {}".format(self.targetMAC)
self.gatewayIP = gateway
print "[+] Gateway IP Address: {}".format(self.gatewayIP)
self.gatewayMAC = resolve_mac(self.gatewayIP)
print "[+] Gateway MAC Address: {}".format(self.gatewayMAC)
#if not self.targetMAC or not self.gatewayMAC:
# print "[!] Failed to resolve MAC Address, check if IP Address is online, exiting ..."
#exit(0)
animation = "|/-\\"
for i in range(15):
time.sleep(0.1)
sys.stdout.write("\r" + "[" + animation[i % len(animation)] + "]" + " Loading SSL Kill ...")
sys.stdout.flush()
self.ArpPoisoner()
sys.stdout.write("\n[+] ARP Poisoner thread loaded")
self.DnsPoisoner()
print "\n[+] DNS Poisoner thread loaded"
if debug:
print "\n[+]Debugger is on!"
else:
print "\n[-]Debugger is off!"
def __init__(self):
self.param = {
"SCRATCH_IP": "127.0.0.1",
"SCRATCH_PORT": 58266,
"ESP_PORT": 9876,
"ESP_LISTEN_IP": "",
"ESP_LISTEN_PORT": 9877,
"ESP_BUFFER": 1024,
"ESP_PRECISION": 0.001,
"ESP_ACK_TIMEOUT": 0.200,
"ESP_POLL_INTERVAL": 0.500,
"ESP_POLL_CMD": "poll",
"ESP_FORCE_ACK_DEBUG": False,
"ESP_POLL_NL": 64,
}
self.const = {
# Pin modes.
# except from UNAVAILABLE taken from Firmata.h
"UNAVAILABLE": -1,
"INPUT": 0, # as defined in wiring.h
"OUTPUT": 1, # as defined in wiring.h
"ANALOG": 2, # analog pin in analogInput mode
"PWM": 3, # digital pin in PWM output mode
"SERVO": 4, # digital pin in SERVO mode
# Pin digit values
"LOW": 0,
"HIGH": 1,
# Response to Scratch
"RESPONSE_OK": "okay"
}
self.name2id = {}
self.id2name = {}
self.name_value_re = re.compile(r"^name ([\w-]*)|;name ([\w-]*)")
self.processOptions()
self.code_to_mode = {
self.UNAVAILABLE: "UNAVAILABLE",
self.INPUT: "Digital%20Input",
self.OUTPUT: "Digital%20Output",
self.ANALOG: "Analog%20Input",
self.PWM: "Analog%20Output(PWM)",
self.SERVO: "Servo"
}
self.mode_to_code = {}
for c, m in self.code_to_mode.iteritems():
self.mode_to_code[m] = c
self.ipNetwork = None
self.espHandlersByDevice = {}
self.espHandlersByIp = {}
self.lastCmdTs = -1
def __init__(self, config):
"""
Read timeout and database configurations from config object
"""
self.config = config
self.buffer = {}
self.addtimes = {}
self.active_keys = []
self.lock = Lock()
self.timeout = 600
if self.config.has_section("CacheConfig"):
if self.config.has_option("CacheConfig", "timeout"):
self.timeout = self.config.getint("CacheConfig", "timeout")
self.oldest = None
self.batch_ready = Queue()
self.send_in_progress = False
self.heads = {"Content-Type" : "application/octet-stream"}
self.dbs = {}
self.db_hosts = {}
self.def_db_host = { "hostname" : "localhost",
"port" : 8086,
"username" : "testuser",
"password" : "testpass",
"maxsend" : 1000,
"batch" : 10,
"maxcache" : 2000,
"timeout" : 10,
"maxdbs" : 1000,
"activedbs" : [],
"exclude" : "",
"create_db" : False}
self.read_db("AdminDB")
if self.config.has_section("SplitConfig"):
if self.config.has_option("SplitConfig", "dbentries"):
l_dbentries = re.split("\s*,\s*", self.config.get("SplitConfig", "dbentries"))
for db in l_dbentries:
splitdb = "SplitDB-%s" % db
self.read_db(splitdb)
def __init__(self, interface, target, gateway):
print banner
print
self.interface = interface
print "[+] Interface: {}".format(self.interface)
def nic_ip(interface):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915,
struct.pack('256s', interface[:15])
)[20:24])
except IOError:
print "[!] Select a valid network interface, exiting ..."
exit(0)
def nic_mac(interface):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', interface[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
self.hostIP = nic_ip(self.interface)
print "[+] This host IP Address: {}".format(self.hostIP)
self.hostMAC = nic_mac(self.interface)
print "[+] This host MAC Address: {}".format(self.hostMAC)
def resolve_mac(ip):
try:
conf.verb = 0
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(op="who-has", pdst=ip), timeout=2)
for snd, rcv in ans:
return str(rcv[Ether].src)
except socket.gaierror:
print "[!] Select a valid IP Address as target/gateway, exiting ..."
exit(0)
self.targetIP = target
print "[+] Target IP Address: {}".format(self.targetIP)
self.targetMAC = resolve_mac(self.targetIP)
print "[+] Target MAC Address: {}".format(self.targetMAC)
self.gatewayIP = gateway
print "[+] Gateway IP Address: {}".format(self.gatewayIP)
self.gatewayMAC = resolve_mac(self.gatewayIP)
print "[+] Gateway MAC Address: {}".format(self.gatewayMAC)
#if not self.targetMAC or not self.gatewayMAC:
# print "[!] Failed to resolve MAC Address, check if IP Address is online, exiting ..."
#exit(0)
animation = "|/-\\"
for i in range(15):
time.sleep(0.1)
sys.stdout.write("\r" + "[" + animation[i % len(animation)] + "]" + " Loading SSL Kill ...")
sys.stdout.flush()
self.ArpPoisoner()
sys.stdout.write("\n[+] ARP Poisoner thread loaded")
self.DnsPoisoner()
print "\n[+] DNS Poisoner thread loaded"
if debug:
print "\n[+]Debugger is on!"
else:
print "\n[-]Debugger is off!"