コード例 #1
0
ファイル: sock_diag.py プロジェクト: 5up3rc/python_netlink
def get_sock_diag(hdr, payload_parser):
    con = netlink.new_sock_diag()
    con.send(hdr)
    msgs = []
    goout = False
    while True:
        d = con.recv(65533)
        b = cStringIO.StringIO(d)
        while True:
            if b.tell() >= len(d):
                break
            msg = netlink.parse_nlmsg(b)
            if msg["type"] == netlink.DONE:
                goout = True
                break
            elif msg["type"] == netlink.ERROR:
                raise ValueError(msg)
            mlen = b.tell() - 16 + msg["len"]
            payload = payload_parser(b)
            attrs = netlink.parse_attrs(b, mlen)
            msgs.append({"msg": msg, "payload": payload, "attrs": attrs})
        if goout:
            break
    b.close()
    return msgs
コード例 #2
0
ファイル: getaddr.py プロジェクト: maliubiao/python_netlink
def getaddr_inet():
    con = netlink.new_route()
    payload = netlink.route_getaddr(netlink.AF_INET, 0x12345) 
    con.send(payload)
    msgs = []
    goout = False
    while True: 
        d = con.recv(65533)
        b = cStringIO.StringIO(d)
        while True:
            if b.tell() >= len(d):
                break
            msg = netlink.parse_nlmsg(b) 
            if msg["type"] == netlink.DONE:
                goout = True
                break
            elif msg["type"] == netlink.ERROR:
                raise ValueError(msg)
            mlen = b.tell() - 16 + msg["len"] 
            payload = netlink.parse_ifaddr(b) 
            attrs = netlink.parse_attrs(b, mlen) 
            msgs.append({
                "msg": msg,
                "payload": payload,
                "attrs": attrs
                })
        if goout:
            break
    b.close()
    return msgs
コード例 #3
0
ファイル: getaddr.py プロジェクト: 5up3rc/python_netlink
def getaddr_inet():
    con = netlink.new_route()
    payload = netlink.route_getaddr(netlink.AF_INET, 0x12345)
    con.send(payload)
    msgs = []
    goout = False
    while True:
        d = con.recv(65533)
        b = cStringIO.StringIO(d)
        while True:
            if b.tell() >= len(d):
                break
            msg = netlink.parse_nlmsg(b)
            if msg["type"] == netlink.DONE:
                goout = True
                break
            elif msg["type"] == netlink.ERROR:
                raise ValueError(msg)
            mlen = b.tell() - 16 + msg["len"]
            payload = netlink.parse_ifaddr(b)
            attrs = netlink.parse_attrs(b, mlen)
            msgs.append({"msg": msg, "payload": payload, "attrs": attrs})
        if goout:
            break
    b.close()
    return msgs
コード例 #4
0
ファイル: if.py プロジェクト: 5up3rc/python_netlink
def get_ifindex(index):
    con = netlink.new_route()
    con.send(netlink.route_getlink(index, 0x20141015))
    d = con.recv(4096)
    b = cStringIO.StringIO(d)
    msg = netlink.parse_nlmsg(b)
    payload = netlink.parse_ifinfo(b)
    attrs = netlink.parse_attrs(b, len(d))
    con.close()
    b.close()
    return {"msg": msg, "payload": payload, "attrs": attrs}
コード例 #5
0
ファイル: if.py プロジェクト: maliubiao/python_netlink
def get_ifindex(index): 
    con = netlink.new_route()
    con.send(netlink.route_getlink(index, 0x20141015))
    d = con.recv(4096) 
    b = cStringIO.StringIO(d)
    msg = netlink.parse_nlmsg(b)
    payload = netlink.parse_ifinfo(b)
    attrs = netlink.parse_attrs(b, len(d)) 
    con.close() 
    b.close()
    return {
            "msg": msg,
            "payload": payload,
            "attrs": attrs
            } 
コード例 #6
0
def get_iface():
    con = netlink.new_generic()
    hdr  = netlink.new_genlmsg(
            {
                "cmd": netlink.NL80211_CMD_GET_SCAN,
                "version": 0,
                "reserved": 0
                }
            ) 
    attr = netlink.newnlattr(netlink.NL80211_ATTR_IFINDEX, netlink.new_policy_u32(3)) 
    payload = netlink.generic_wireless(hdr+attr, 0x12345) 
    con.send(payload) 
    d = con.recv(4096)
    b = cStringIO.StringIO(d)
    msg = netlink.parse_nlmsg(b)
    mlen = b.tell() - 16 + msg["len"]
    payload = netlink.parse_genlmsg(b) 
    attrs = netlink.parse_attrs(b, mlen) 
    return {
            "msg": msg,
            "payload": payload,
            "attrs": attrs
            }
コード例 #7
0
ファイル: test-netlink-1.py プロジェクト: li-ma/homework
def get_family():
    con = netlink.new_generic()
    hdr  = netlink.new_genlmsg(
            {
                "cmd": netlink.CTRL_CMD_GETFAMILY,
                "version": 0,
                "reserved": 0
                }
            )
    payload = netlink.generic_id_ctrl(hdr,0x12345)
    con.send(payload)
    msgs = []
    goout = False
    while True:
        d = con.recv(65533)
        b = cStringIO.StringIO(d)
        while True:
            if b.tell() >= len(d):
                break
            msg = netlink.parse_nlmsg(b)
            if msg["type"] == netlink.DONE:
                goout = True
                break
            elif msg["type"] == netlink.ERROR:
                raise ValueError(msg)
            mlen = b.tell() - 16 + msg["len"]
            payload = netlink.parse_genlmsg(b)
            attrs = netlink.parse_attrs(b, mlen)
            msgs.append({
                "msg": msg,
                "payload": payload,
                "attrs": attrs
                })
        if goout:
            break
    b.close()
    return msgs
コード例 #8
0
def get_family():
    con = netlink.new_generic()
    hdr  = netlink.new_genlmsg(
            {
                "cmd": netlink.CTRL_CMD_GETFAMILY,
                "version": 0,
                "reserved": 0
                }
            ) 
    payload = netlink.generic_id_ctrl(hdr,0x12345) 
    con.send(payload)
    msgs = []
    goout = False 
    while True: 
        d = con.recv(65533)
        b = cStringIO.StringIO(d)
        while True:
            if b.tell() >= len(d):
                break
            msg = netlink.parse_nlmsg(b) 
            if msg["type"] == netlink.DONE:
                goout = True
                break
            elif msg["type"] == netlink.ERROR:
                raise ValueError(msg)
            mlen = b.tell() - 16 + msg["len"] 
            payload = netlink.parse_genlmsg(b) 
            attrs = netlink.parse_attrs(b, mlen) 
            msgs.append({
                "msg": msg,
                "payload": payload,
                "attrs": attrs
                })
        if goout:
            break
    b.close() 
    return msgs