示例#1
0
文件: tools.py 项目: spofa/monkey
def get_interface_to_target(dst):
    if sys.platform == "win32":
        try:
            import dnet
            intf = dnet.intf()
            inte = intf.get_dst(dnet.addr(dst))
            return str(inte['addr']).split("/")[0]
        except ImportError:
            # dnet lib is not installed
            return get_close_matches(dst, local_ips())[0]
    else:
        # based on scapy implementation

        def atol(x):
            ip = socket.inet_aton(x)
            return struct.unpack("!I", ip)[0]

        routes = get_routes()
        dst = atol(dst)
        pathes = []
        for d, m, gw, i, a in routes:
            aa = atol(a)
            if aa == dst:
                pathes.append((0xffffffffL, ("lo", a, "0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m, (i, a, gw)))
        if not pathes:
            return None
        pathes.sort()
        ret = pathes[-1][1]
        return ret[1]
示例#2
0
文件: tools.py 项目: xuacker/monkey
def get_interface_to_target(dst):
    if sys.platform == "win32":
        ips = local_ips()
        matches = get_close_matches(dst, ips)
        return matches[0] if (len(matches) > 0) else ips[0]
    else:
        # based on scapy implementation

        def atol(x):
            ip = socket.inet_aton(x)
            return struct.unpack("!I", ip)[0]

        routes = get_routes()
        dst = atol(dst)
        pathes = []
        for d, m, gw, i, a in routes:
            aa = atol(a)
            if aa == dst:
                pathes.append((0xffffffff, ("lo", a, "0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m, (i, a, gw)))
        if not pathes:
            return None
        pathes.sort()
        ret = pathes[-1][1]
        return ret[1]
示例#3
0
def get_interface_to_target(dst):
    if sys.platform == "win32":
        ips = local_ips()
        matches = get_close_matches(dst, ips)
        return matches[0] if (len(matches) > 0) else ips[0]
    else:
        # based on scapy implementation

        def atol(x):
            ip = socket.inet_aton(x)
            return struct.unpack("!I", ip)[0]

        routes = get_routes()
        dst = atol(dst)
        pathes = []
        for d, m, gw, i, a in routes:
            aa = atol(a)
            if aa == dst:
                pathes.append((0xffffffffL, ("lo", a, "0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m, (i, a, gw)))
        if not pathes:
            return None
        pathes.sort()
        ret = pathes[-1][1]
        return ret[1]
示例#4
0
def get_interface_to_target(dst):
    if sys.platform == "win32":
        try:
            import dnet
            intf = dnet.intf()
            inte = intf.get_dst(dnet.addr(dst))
            return str(inte['addr']).split("/")[0]
        except ImportError:
            # dnet lib is not installed
            return get_close_matches(dst, local_ips())[0]
    else:
        # based on scapy implementation

        def atol(x):
            ip = socket.inet_aton(x)
            return struct.unpack("!I", ip)[0]

        routes = get_routes()
        dst = atol(dst)
        pathes = []
        for d, m, gw, i, a in routes:
            aa = atol(a)
            if aa == dst:
                pathes.append((0xffffffffL, ("lo", a, "0.0.0.0")))
            if (dst & m) == (d & m):
                pathes.append((m, (i, a, gw)))
        if not pathes:
            return None
        pathes.sort()
        ret = pathes[-1][1]
        return ret[1]
示例#5
0
文件: tools.py 项目: 0x0mar/monkey
    def create_transfer(host, src_path, local_ip=None, local_port=None):
        if not local_port:
            local_port = get_free_tcp_port()

        if not local_ip:
            local_ip = get_close_matches(host.ip_addr, local_ips())[0]

        if not firewall.listen_allowed():
            return None, None

        httpd = HTTPServer(local_ip, local_port, src_path)
        httpd.daemon = True
        httpd.start()

        return "http://%s:%s/%s" % (local_ip, local_port, urllib.quote(os.path.basename(src_path))), httpd
示例#6
0
    def create_transfer(host, src_path, local_ip=None, local_port=None):
        if not local_port:
            local_port = get_free_tcp_port()

        if not local_ip:
            local_ip = get_close_matches(host.ip_addr, local_ips())[0]

        if not firewall.listen_allowed():
            return None, None

        httpd = HTTPServer(local_ip, local_port, src_path)
        httpd.daemon = True
        httpd.start()

        return "http://%s:%s/%s" % (local_ip, local_port,
                                    urllib.quote(
                                        os.path.basename(src_path))), httpd