Exemple #1
0
def IcmpSendEcho(handle, addr, data, options, timeout):
    reply = ICMP_ECHO_REPLY()
    data = data or ''
    if options:
        options = ctypes.byref(options)
    r = icmp.IcmpSendEcho(handle, inet_addr(addr),
                          data, len(data),
                          options,
                          ctypes.byref(reply),
                          ctypes.sizeof(ICMP_ECHO_REPLY) + len(data),
                          timeout)
    return str(reply.Address), reply.Status, reply.RoundTripTime
Exemple #2
0
def get_route_ip(ip=None):
    #ip = socket.gethostbyname('bittorrent.com')
    # doesn't really matter if this is out of date, we're just trying to find
    # the interface to get to the internet.
    ip = ip or '38.99.5.27'
    ip = inet_addr(ip)

    index = ctypes.c_ulong()
    Iphlpapi.GetBestInterface(ip, ctypes.byref(index))
    index = long(index.value)
    try:
        interface_ip = get_interface_by_index(index)
    except:
        interface_ip = None
    return interface_ip