没有项目描述
mudd的Python项目详细描述
泥泞
muddy是一个用于生成mud文件(RFC8520)的python包和cli工具。
用法
根据抽象级别的不同,有多种方法可以生成mud对象:
frommuddy.makerimportmake_mudfrommuddy.modelsimportDirection,IPVersion,Protocol,MatchTypemud=make_mud(1,'https://lighting.example.com/lightbulb2000',48,True,'The BMS Example Light Bulb','https://lighting.example.com/lightbulb2000/documentation',[Direction.TO_DEVICE,Direction.FROM_DEVICE],IPVersion.IPV4,'test.example.com',Protocol.ANY,MatchType.IS_MYMFG,[88,443],[88,443])
或
frommuddy.makerimportmake_mud,make_support_infofrommuddy.modelsimportDirection,IPVersion,Protocol,MatchTypesupport_info=make_support_info(1,'https://lighting.example.com/lightbulb2000',48,True,'The BMS Example Light Bulb','https://lighting.example.com/lightbulb2000/documentation')mud=make_mud(support_info,[Direction.TO_DEVICE,Direction.FROM_DEVICE],IPVersion.IPV4,'test.example.com',Protocol.ANY,[88,443],[88,443],MatchType.IS_MYMFG)
或
frommuddy.makerimportmake_mud,make_acl_names,make_policy,make_aclsfrommuddy.modelsimportDirection,IPVersion,Protocol,MatchTypeimportrandommud_name=f'mud-{random.randint(10000, 99999)}'acl=[]policies={}fordirection_initiatedin[Direction.TO_DEVICE,Direction.FROM_DEVICE]:acl_names=make_acl_names(mud_name,IPVersion.IPV4,direction_initiated)policies.update(make_policy(direction_initiated,acl_names))acl.append(make_acls([IPVersion.IPV4],'test.example.com',Protocol.ANY,[88,443],[88,443],MatchType.IS_MYMFG,direction_initiated,acl_names))mud=make_mud(policies,acl,1,'https://lighting.example.com/lightbulb2000',48,True,'The BMS Example Light Bulb','https://lighting.example.com/lightbulb2000/documentation')
或
frommuddy.makerimportmake_mud,make_acl_names,make_policy,make_acls,make_support_infofrommuddy.modelsimportDirection,IPVersion,Protocol,MatchTypeimportrandomsupport_info=make_support_info(1,'https://lighting.example.com/lightbulb2000',48,True,'The BMS Example Light Bulb','https://lighting.example.com/lightbulb2000/documentation')mud_name=f'mud-{random.randint(10000, 99999)}'acl=[]policies={}fordirection_initiatedin[Direction.TO_DEVICE,Direction.FROM_DEVICE]:acl_names=make_acl_names(mud_name,IPVersion.IPV4,direction_initiated)policies.update(make_policy(direction_initiated,acl_names))acl.append(make_acls([IPVersion.IPV4],'test.example.com',Protocol.ANY,[88,443],[88,443],MatchType.IS_MYMFG,direction_initiated,acl_names))mud=make_mud(support_info,policies,acl)
要获取mud对象的json,您只需json.dumps(mud)
。
示例输出
{"ietf-mud:mud":{"mud-version":1,"mud-url":"https://lighting.example.com/lightbulb2000","last-update":"2019-07-23T19:54:24","cache-validity":48,"is-supported":true,"systeminfo":"The BMS Example Light Bulb","documentation":"https://lighting.example.com/lightbulb2000/documentation","to-device-policy":{"access-lists":{"access-list":[{"name":"mud-52892-v4to"}]}},"from-device-policy":{"access-lists":{"access-list":[{"name":"mud-52892-v4fr"}]}}},"ietf-access-control-list:acls":{"acl":[{"name":"mud-52892-v4to","type":"ipv4","aces":{"ace":[{"name":"myman0-todev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman1-todev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman1-todev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman2-todev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}}]}},{"name":"mud-52892-v4fr","type":"ipv4","aces":{"ace":[{"name":"myman0-frdev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman1-frdev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman1-frdev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}},{"name":"myman2-frdev","matches":{"ietf-mud:mud":{"same-manufacturer":[]}},"actions":{"forwarding":"accept"}}]}}]}}