網絡常用python函數

字符串mac地址轉換:

def str2mac(s):
    return ("%02x:" * 6)[:-1] % tuple(orb(x) for x in s)

mac地址轉字符串:

def mac2str(mac):
    return b"".join(chb(int(x, 16)) for x in plain_str(mac).split(':'))

參考鏈接:
https://github.com/secdev/scapy/blob/2e87889089e5593988911309bb4a1ca4f632d716/scapy/utils.py#L467

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章