本文整理汇总了Python中socket.setdefaulttimeout方法的典型用法代码示例。如果您正苦于以下问题:Python socket.setdefaulttimeout方法的具体用法?Python socket.setdefaulttimeout怎么用?Python socket.setdefaulttimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket
的用法示例。
在下文中一共展示了socket.setdefaulttimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_network
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def check_network(args):
print('----------Network Test----------')
if args.timeout > 0:
print('Setting timeout: {}'.format(args.timeout))
socket.setdefaulttimeout(10)
for region in args.region.strip().split(','):
r = region.strip().lower()
if not r:
continue
if r in REGIONAL_URLS:
URLS.update(REGIONAL_URLS[r])
else:
import warnings
warnings.warn('Region {} do not need specific test, please refer to global sites.'.format(r))
for name, url in URLS.items():
test_connection(name, url, args.timeout)
示例2: check
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def check(url, ip, ports, apps):
if verify(vuln, ports, apps):
socket.setdefaulttimeout(2)
port = 11211
payload = b'\x73\x74\x61\x74\x73\x0a' # command:stats
s = socket.socket()
socket.setdefaulttimeout(5)
try:
s.connect((ip, port))
s.send(payload)
recvdata = s.recv(2048) # response larger than 1024
s.close()
if recvdata and (b'STAT version' in recvdata):
return '11211 Memcache Unauthorized Access'
except Exception as e:
print(e)
示例3: check
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def check(url, ip, ports, apps):
if verify(vuln, ports, apps):
try:
socket.setdefaulttimeout(1.5)
payload = b"\x40\x52\x53\x59\x4e\x43\x44\x3a\x20\x33\x31\x2e\x30\x0a"
socket.setdefaulttimeout(timeout)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (ip, 873)
sock.connect(server_address)
sock.sendall(payload)
initinfo = sock.recv(400)
if b"RSYNCD" in initinfo:
sock.sendall(b"\x0a")
modulelist = sock.recv(200)
sock.close()
if len(modulelist) > 0:
return '873 Rsync Unauthorized Access'
except Exception as e:
pass
示例4: check
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def check(ip, port, timeout):
try:
socket.setdefaulttimeout(timeout)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
flag = "GET /?order[updatexml(1,concat(0x3a,user()),1)]=1 HTTP/1.1"
s.send(flag)
time.sleep(1)
data = s.recv(1024)
s.close()
if 'GET' in data:
url = 'http://' + ip + ":" + str(port) + '/?order[updatexml(1,concat(0x3a,user()),1)]=1'
request = urllib2.Request(url)
res_html = urllib2.urlopen(request, timeout=timeout).read(204800)
if 'root' in res_html:
return u"ThinkPHP 3.X order by注入漏洞"
except Exception, e:
pass
示例5: _verify
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def _verify(self):
import socket
#调用指纹方法
result={}
output = Output(self)
message = ''
try:
s = socket.socket()
socket.setdefaulttimeout(1)#两秒超时
port = 873
ip = self.url.split(':')[1].replace('/','')
s.connect((ip, port))
print('Rsync未授权访问')
message = 'Rsync 873端口 未授权访问'
result['VerifyInfo'] = {}
result['VerifyInfo']['url'] = ip
result['VerifyInfo']['Payload'] = message
except Exception as e:
print(e)
s.close()
print '[+]30 poc done'
return self.save_output(result)
示例6: _setHTTPTimeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def _setHTTPTimeout():
"""
Set the HTTP timeout
"""
if conf.timeout:
infoMsg = "setting the HTTP timeout"
logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)
conf.timeout = float(conf.timeout)
if conf.timeout < 3.0:
warnMsg = "the minimum HTTP timeout is 3 seconds, pocsuite will going to reset it"
logger.log(CUSTOM_LOGGING.WARNING, warnMsg)
conf.timeout = 3.0
else:
conf.timeout = 30.0
socket.setdefaulttimeout(conf.timeout)
示例7: downloadAndShow
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def downloadAndShow(self):
"""Triggered when the user wants to download and see the file"""
url = self.selectedText.strip()
if url.lower().startswith("www."):
url = "http://" + url
oldTimeout = socket.getdefaulttimeout()
newTimeout = 5 # Otherwise the pause is too long
socket.setdefaulttimeout(newTimeout)
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
try:
response = urllib.request.urlopen(url)
content = decodeURLContent(response.read())
# The content has been read sucessfully
mainWindow = GlobalData().mainWindow
mainWindow.editorsManager().newTabClicked(content,
os.path.basename(url))
except Exception as exc:
logging.error("Error downloading '" + url + "'\n" + str(exc))
QApplication.restoreOverrideCursor()
socket.setdefaulttimeout(oldTimeout)
示例8: main
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def main():
ports = [21,23,22]
ips = "192.168.195."
for octet in range(0,255):
for port in ports:
ip = ips + str(octet)
#print("[*] Testing port %s at IP %s") % (port, ip)
try:
socket.setdefaulttimeout(1)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((ip,port))
output = s.recv(1024)
print("[+] The banner: %s for IP: %s at Port: %s") % (output,ip,port)
except:
print("[-] Failed to Connect to %s:%s") % (ip, port)
finally:
s.close()
示例9: internet
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def internet(host="8.8.8.8", port=53, timeout=10):
"""
Check Internet Connections.
:param host: the host that check connection to
:param port: port that check connection with
:param timeout: times that check the connnection
:type host:str
:type port:int
:type timeout:int
:return bool: True if Connection is Stable
>>> internet() # if there is stable internet connection
True
>>> internet() # if there is no stable internet connection
False
"""
try:
socket.setdefaulttimeout(timeout)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except Exception as ex:
return False
示例10: filter_proxy
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def filter_proxy(self):
"""
将不可用IP剔除
:return:
"""
socket.setdefaulttimeout(1)
path = os.path.join(os.path.dirname(__file__), './proxy_list')
f = open(path, "w")
head = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
'Connection': 'keep-alive'}
url = "http://icanhazip.com"
proxy_num = 0
for proxy in self.proxy_list:
proxy_temp = {"https": "https://{}".format(proxy)}
try:
req = requests.get(url, proxies=proxy_temp, timeout=2, headers=head).content
print(req)
write_proxy = proxy + "\n"
f.write(write_proxy)
proxy_num += 1
except Exception:
print ("代理链接超时,去除此IP:{0}".format(proxy))
continue
print("总共可使用ip量为{}个".format(proxy_num))
示例11: _collect_aws_data
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def _collect_aws_data(cmd=''):
aws_rsp = ''
aws_timeout = 1
socket.setdefaulttimeout(aws_timeout)
aws_metadata_base_url = 'http://169.254.169.254/latest/meta-data'
out = "['AWS']"
try:
req = urllib.request.Request(aws_metadata_base_url)
r = urllib.request.urlopen(req)
# r = requests.get(aws_metadata_base_url,timeout=aws_timeout)
if r.code == 200:
rsp = r.read()
aws_rsp += _get_aws_metadata(rsp, '/')
out += "\n" + "Requesting... {0} \n{1} \t Successful".format(aws_metadata_base_url, aws_rsp)
else:
aws_rsp = " Not likely in AWS"
out += "\n" + "Requesting... {0} \t FAILED {1} ".format(aws_metadata_base_url, aws_rsp)
except Exception as e:
out += "\n" + "Requesting... {0} \t {1} ".format(aws_metadata_base_url, e)
out += "\n" + "FAILED! Node Is Not likely In AWS"
return out, None
示例12: _collect_gce_data
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def _collect_gce_data(cmd=''):
gce_timeout = 1
socket.setdefaulttimeout(gce_timeout)
gce_metadata_base_url = 'http://metadata.google.internal/computeMetadata/v1/instance/'
out = "['GCE']"
fields_to_ignore = ['attributes/']
try:
req = urllib.request.Request(gce_metadata_base_url, headers={"Metadata-Flavor" : "Google"})
r = urllib.request.urlopen(req)
if r.code == 200:
rsp = r.read()
gce_rsp = _get_gce_metadata(rsp, fields_to_ignore=fields_to_ignore)
out += "\n" + "Requesting... {0} \n{1} \t Successful".format(gce_metadata_base_url, gce_rsp)
else:
gce_rsp = " Not likely in GCE"
out += "\n" + "Requesting... {0} \t FAILED {1} ".format(gce_metadata_base_url, gce_rsp)
except Exception as e:
out += "\n" + "Requesting... {0} \t {1} ".format(gce_metadata_base_url, e)
out += "\n" + "FAILED! Node Is Not likely In GCE"
return out, None
示例13: _collect_azure_data
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def _collect_azure_data(cmd=''):
azure_timeout = 1
socket.setdefaulttimeout(azure_timeout)
azure_metadata_base_url = 'http://169.254.169.254/metadata/instance?api-version=2017-04-02'
out = "['Azure']"
try:
req = urllib.request.Request(azure_metadata_base_url, headers={"Metadata" : "true"})
r = urllib.request.urlopen(req)
if r.code == 200:
rsp = r.read()
rsp = rsp.decode("utf-8")
jsonObj = json.loads(rsp)
out += "\n" + "Requesting... {0} \n{1} \t Successful".format(azure_metadata_base_url,
json.dumps(jsonObj, sort_keys=True, indent=4, separators=(',', ': ')))
else:
rsp = " Not likely in Azure"
out += "\n" + "Requesting... {0} \t FAILED {1} ".format(azure_metadata_base_url, rsp)
except Exception as e:
out += "\n" + "Requesting... {0} \t {1} ".format(azure_metadata_base_url, e)
out += "\n" + "FAILED! Node Is Not likely In Azure"
return out, None
示例14: test_timeout
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def test_timeout(self):
old_timeout = socket.getdefaulttimeout()
try:
socket.setdefaulttimeout(0.1)
parent, child = multiprocessing.Pipe(duplex=True)
l = multiprocessing.connection.Listener(family='AF_INET')
p = multiprocessing.Process(target=self._test_timeout,
args=(child, l.address))
p.start()
child.close()
self.assertEqual(parent.recv(), 123)
parent.close()
conn = l.accept()
self.assertEqual(conn.recv(), 456)
conn.close()
l.close()
p.join(10)
finally:
socket.setdefaulttimeout(old_timeout)
#
# Test what happens with no "if __name__ == '__main__'"
#
示例15: get_browser
# 需要导入模块: import socket [as 别名]
# 或者: from socket import setdefaulttimeout [as 别名]
def get_browser(self):
'''Returns a mechanize.Browser object configured with the framework's global options.'''
br = mechanize.Browser()
# set the user-agent header
br.addheaders = [('User-agent', self._global_options['user-agent'])]
# set debug options
if self._global_options['verbosity'] >= 2:
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
# set proxy
if self._global_options['proxy']:
br.set_proxies({'http': self._global_options['proxy'], 'https': self._global_options['proxy']})
# additional settings
br.set_handle_robots(False)
# set timeout
socket.setdefaulttimeout(self._global_options['timeout'])
return br