没有项目描述

mudd的Python项目详细描述


泥泞

PyPI version

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"}}]}}]}}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
ws-consumer服务地址中的java动态属性   java如何比较整数列表,然后按升序排序?   javascript我正在使用java脚本调用一个函数,但它没有调用代码下面的方法,也没有调用secretitnames()函数   在文本窗格中多次使用Java insertIcon图标   JavaMSAL安卓。AuthenticationActivity完成,但用于身份验证请求的线程池线程仍处于等待状态   if语句中的java多范围比较   java toString()表示输出   java如何在jcstrest测试中生成指令重新排序   java我怎样才能运行它?   web应用程序中使用Hibernate和Spring的java问题   如何将字符串数据写入Java文本文件   如何在java命令提示符下运行已签名的jar文件?   java从我的菜单调用RCP应用程序   java如何等待Canvas/GraphicsContext完成任务,然后再继续执行代码块?