• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python network.check_tcp_port函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中ralph.util.network.check_tcp_port函数的典型用法代码示例。如果您正苦于以下问题:Python check_tcp_port函数的具体用法?Python check_tcp_port怎么用?Python check_tcp_port使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了check_tcp_port函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: ssh_linux

def ssh_linux(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gmodel not in {'Linux', 'ESX', 'XEN'}:
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    ip = str(kwargs['ip'])
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    ssh = None
    auths = [
        (settings.SSH_USER or 'root', settings.SSH_PASSWORD),
        (settings.XEN_USER, settings.XEN_PASSWORD),
    ]
    try:
        for user, password in auths:
            if user is None or password is None:
                continue
            try:
                ssh = network.connect_ssh(ip, user, password)
            except network.AuthError:
                pass
            else:
                break
        else:
            return False, 'Authorization failed', kwargs
        name = run_ssh_linux(ssh, ip)
    except (network.Error, paramiko.SSHException) as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:30,代码来源:ssh_linux.py


示例2: ssh_linux

def ssh_linux(**kwargs):
    if "nx-os" in kwargs.get("snmp_name", "").lower():
        return False, "incompatible Nexus found.", kwargs
    kwargs["guessmodel"] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gmodel not in {"Linux", "ESX", "XEN"}:
        return False, "no match: %s %s" % (gvendor, gmodel), kwargs
    ip = str(kwargs["ip"])
    if not network.check_tcp_port(ip, 22):
        return False, "closed.", kwargs
    ssh = None
    auths = [(settings.SSH_USER or "root", settings.SSH_PASSWORD), (settings.XEN_USER, settings.XEN_PASSWORD)]
    try:
        for user, password in auths:
            if user is None or password is None:
                continue
            try:
                ssh = network.connect_ssh(ip, user, password)
            except network.AuthError:
                pass
            else:
                break
        else:
            return False, "Authorization failed", kwargs
        name = run_ssh_linux(ssh, ip)
    except (network.Error, paramiko.SSHException) as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:jjagodzinski,项目名称:ralph,代码行数:27,代码来源:ssh_linux.py


示例3: ssh_onstor

def ssh_onstor(**kwargs):
    if SSH_ONSTOR_USER is None or SSH_ONSTOR_PASSWORD is None:
        return False, 'no credentials.', kwargs
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    ip = str(kwargs['ip'])
    if kwargs.get('http_family') not in ('sscccc',):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        DiscoveryWarning(
            message="Port 22 closed on an Onstor device.",
            plugin=__name__,
            ip=ip,
        ).save()
        return False, 'closed.', kwargs
    try:
        name = _run_ssh_onstor(ip)
    except (network.Error, Error, paramiko.SSHException) as e:
        DiscoveryWarning(
            message="This is an Onstor, but: " + str(e),
            plugin=__name__,
            ip=ip,
        ).save()
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:szaydel,项目名称:ralph,代码行数:25,代码来源:ssh_onstor.py


示例4: ssh_xen

def ssh_xen(**kwargs):
    ip = str(kwargs['ip'])
    if XEN_USER is None:
        return False, 'no auth.', kwargs
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    if 'xen' not in kwargs.get('snmp_name', ''):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        DiscoveryWarning(
            message="Port 22 closed on a XEN server.",
            plugin=__name__,
            ip=ip,
        ).save()
        return False, 'closed.', kwargs
    ipaddr = IPAddress.objects.get(address=ip)
    dev = ipaddr.device
    if dev is None:
        return False, 'no device.', kwargs
    try:
        name = run_ssh_xen(ipaddr, dev)
    except (network.Error, Error, paramiko.SSHException) as e:
        DiscoveryWarning(
            message="This is a XEN, but: " + str(e),
            plugin=__name__,
            ip=ip,
        ).save()
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:szaydel,项目名称:ralph,代码行数:29,代码来源:ssh_xen.py


示例5: ssh_ibm_bladecenter

def ssh_ibm_bladecenter(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    ip = str(kwargs['ip'])
    if kwargs.get('http_family', '') not in ('IBM', 'Unspecified'):
        return False, 'no match.', kwargs
    if not kwargs.get('snmp_name', 'IBM').startswith('IBM'):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        DiscoveryWarning(
            message="Port 22 closed on an IBM BladeServer.",
            plugin=__name__,
            ip=ip,
        ).save()
        return False, 'closed.', kwargs
    try:
        name = run_ssh_bladecenter(ip)
    except (network.Error, Error, paramiko.SSHException, socket.error) as e:
        DiscoveryWarning(
            message="This is an IBM BladeServer, but: " + str(e),
            plugin=__name__,
            ip=ip,
        ).save()
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:25,代码来源:ssh_ibm_bladecenter.py


示例6: _detect_software

def _detect_software(ip, dev, http_family):
    detected = []
    if network.check_tcp_port(ip, 1521):
        detected.append('Oracle')
        Software.create(dev, 'oracle', 'Oracle', family='Database').save()
    else:
        dev.software_set.filter(path='oracle').all().delete()
    if network.check_tcp_port(ip, 3306):
        detected.append('MySQL')
        Software.create(dev, 'mysql', 'MySQL', family='Database').save()
    else:
        dev.software_set.filter(path='mysql').all().delete()
    if network.check_tcp_port(ip, 80) or network.check_tcp_port(ip, 443):
        detected.append('WWW')
        Software.create(dev, 'www', 'WWW', label=http_family, family='WWW').save()
    else:
        dev.software_set.filter(path='www').all().delete()
    return ', '.join(detected)
开发者ID:iwwwwwwi,项目名称:ralph,代码行数:18,代码来源:software.py


示例7: _connect_ssh

def _connect_ssh(ip_address, user, password):
    if not network.check_tcp_port(ip_address, 22):
        raise ConnectionError('Port 22 closed on a HP MSA Storage.')
    return network.connect_ssh(
        ip_address,
        user,
        password,
        client=HPSSHClient,
    )
开发者ID:alberto-g,项目名称:ralph,代码行数:9,代码来源:ssh_hp_msa.py


示例8: ssh_ganeti

def ssh_ganeti(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    ip = str(kwargs['ip'])
    if not network.check_tcp_port(ip, 22):
        return False, 'port 22 closed.', kwargs
    try:
        name = run_ssh_ganeti(ip)
    except (network.Error, Error, paramiko.SSHException) as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:ReJeCtAll,项目名称:ralph,代码行数:11,代码来源:ssh_ganeti.py


示例9: ssh_cisco_asa

def ssh_cisco_asa(**kwargs):
    ip = str(kwargs["ip"])
    kwargs["guessmodel"] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != "Cisco" or gmodel not in ("",):
        return False, "no match: %s %s" % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, "closed.", kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:relusek,项目名称:ralph,代码行数:14,代码来源:ssh_cisco_asa.py


示例10: ssh_cisco_asa

def ssh_cisco_asa(**kwargs):
    ip = str(kwargs['ip'])
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('',):
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:pijany,项目名称:ralph,代码行数:14,代码来源:ssh_cisco_asa.py


示例11: ssh_proxmox

def ssh_proxmox(**kwargs):
    ip = str(kwargs['ip'])
    if kwargs.get('http_family') not in ('Proxmox',):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_proxmox(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    except Error as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:pb-it,项目名称:ralph,代码行数:15,代码来源:ssh_proxmox.py


示例12: _detect_software

def _detect_software(ip_address, http_family):
    software = []
    if network.check_tcp_port(ip_address, 1521):
        software.append({
            'path': 'oracle',
            'model_name': 'Oracle',
        })
    if network.check_tcp_port(ip_address, 3306):
        software.append({
            'path': 'mysql',
            'model_name': 'MySQL',
        })
    if any((
        network.check_tcp_port(ip_address, 80),
        network.check_tcp_port(ip_address, 443),
    )):
        soft = {
            'path': 'www',
            'model_name': 'WWW',
        }
        if http_family:
            soft['label'] = http_family
        software.append(soft)
    return software
开发者ID:4i60r,项目名称:ralph,代码行数:24,代码来源:software.py


示例13: scan_address

def scan_address(ip_address, **kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        raise NoMatchError("Incompatible Nexus found.")
    if 'StorageWorks' not in kwargs.get('snmp_name'):
        raise NoMatchError("No match")
    if not network.check_tcp_port(ip_address, 22):
        raise ConnectionError("Port 22 closed.")
    device = _run_ssh_p2000(ip_address)
    ret = {
        'status': 'success',
        'device': device,
    }
    tpl = get_base_result_template('ssh_hp_p2000')
    tpl.update(ret)
    return json.loads(json.dumps(tpl))  # to ensure its picklable
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:15,代码来源:ssh_hp_p2000.py


示例14: ssh_ssg

def ssh_ssg(**kwargs):
    ip = str(kwargs['ip'])
    if kwargs.get('http_family') not in ('SSG', 'Unspecified'):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_ssg(ip)
    except network.Error as e:
        return False, str(e), kwargs
    except Error as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:pb-it,项目名称:ralph,代码行数:15,代码来源:ssh_ssg.py


示例15: ssh_cisco_asa

def ssh_cisco_asa(**kwargs):
    ip = str(kwargs['ip'])
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
    if gvendor != 'Cisco' or gmodel not in ('',):
        return False, 'no match: %s %s' % (gvendor, gmodel), kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_asa(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:andrzej-jankowski,项目名称:ralph,代码行数:16,代码来源:ssh_cisco_asa.py


示例16: ssh_proxmox

def ssh_proxmox(**kwargs):
    if 'nx-os' in kwargs.get('snmp_name', '').lower():
        return False, 'incompatible Nexus found.', kwargs
    ip = str(kwargs['ip'])
    if kwargs.get('http_family') not in ('Proxmox',):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = run_ssh_proxmox(ip)
    except (network.Error, Error) as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    except Error as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:iwwwwwwi,项目名称:ralph,代码行数:17,代码来源:ssh_proxmox.py


示例17: ssh_ibm_bladecenter

def ssh_ibm_bladecenter(**kwargs):
    if "nx-os" in kwargs.get("snmp_name", "").lower():
        return False, "incompatible Nexus found.", kwargs
    ip = str(kwargs["ip"])
    if kwargs.get("http_family", "") not in ("IBM", "Unspecified"):
        return False, "no match.", kwargs
    if not kwargs.get("snmp_name", "IBM").startswith("IBM"):
        return False, "no match.", kwargs
    if not network.check_tcp_port(ip, 22):
        DiscoveryWarning(message="Port 22 closed on an IBM BladeServer.", plugin=__name__, ip=ip).save()
        return False, "closed.", kwargs
    try:
        name = run_ssh_bladecenter(ip)
    except (network.Error, Error, paramiko.SSHException, socket.error) as e:
        DiscoveryWarning(message="This is an IBM BladeServer, but: " + str(e), plugin=__name__, ip=ip).save()
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:jjagodzinski,项目名称:ralph,代码行数:17,代码来源:ssh_ibm_bladecenter.py


示例18: ssh_hp_p2000

def ssh_hp_p2000(**kwargs):
    if SSH_P2000_USER is None or SSH_P2000_PASSWORD is None:
        return False, 'no credentials.', kwargs
    ip = str(kwargs['ip'])
    if 'StorageWorks' not in kwargs.get('snmp_name'):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = _run_ssh_p2000(ip)
    except (network.Error, storageworks.Error) as e:
        return False, str(e), kwargs
    except storageworks.Error as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:pijany,项目名称:ralph,代码行数:17,代码来源:ssh_hp_p2000.py


示例19: ssh_hp_msa

def ssh_hp_msa(**kwargs):
    if SSH_MSA_USER is None or SSH_MSA_PASSWORD is None:
        return False, 'no credentials.', kwargs
    ip = str(kwargs['ip'])
    if kwargs.get('http_family') not in ('WindRiver-WebServer',):
        return False, 'no match.', kwargs
    if not network.check_tcp_port(ip, 22):
        return False, 'closed.', kwargs
    try:
        name = _run_ssh_msa(ip)
    except (network.Error, storageworks.Error) as e:
        return False, str(e), kwargs
    except storageworks.Error as e:
        return False, str(e), kwargs
    except paramiko.SSHException as e:
        return False, str(e), kwargs
    return True, name, kwargs
开发者ID:pijany,项目名称:ralph,代码行数:17,代码来源:ssh_hp_msa.py


示例20: scan_address

def scan_address(ip_address, **kwargs):
    if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
        raise NoMatchError('Incompatible Nexus found.')
    if kwargs.get('http_family', '') not in ('IBM', 'Unspecified'):
        raise NoMatchError('It is not IBM.')
    if not (kwargs.get('snmp_name', 'IBM') or 'IBM').startswith('IBM'):
        raise NoMatchError('It is not IBM.')
    if not network.check_tcp_port(ip_address, 22):
        raise ConnectionError('Port 22 closed on an IBM BladeServer.')
    messages = []
    result = get_base_result_template('ssh_ibm_bladecenter', messages)
    device = _blade_scan(ip_address)
    if not device:
        raise DeviceError("Malformed bladecenter device: %s" % ip_address)
    result['device'] = device
    result['status'] = 'success'
    return result
开发者ID:4i60r,项目名称:ralph,代码行数:17,代码来源:ssh_ibm_bladecenter.py



注:本文中的ralph.util.network.check_tcp_port函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python network.connect_ssh函数代码示例发布时间:2022-05-26
下一篇:
Python global_utils.login_as_su函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap