用于python的srv记录解析器
srvresolver的Python项目详细描述
SRV分解器
根据RFC2782从srv地址获取记录的帮助程序。
功能
- 支持记录权重和优先级
- 检查特定端口的服务可用性
- 随机记录选择器
- 支持TTL的缓存
安装
只需使用pip
:
pip install srvresolver
示例
fromsrvresolver.srv_resolverimportSRVResolver# get all recordsSRVResolver.resolve('_service._tcp.example.com')# get one random record with working connection SRVResolver.resolve_random('_service._tcp.example.com')# get first available serverSRVResolver.resolve_first('_service._tcp.example.com')
添加
具有dns缓存的解析器
这一个使用dnspython模块中实现的缓存。
fromsrvresolver.srv_resolver_cachedimportSRVResolverCached# get all recordsSRVResolverCached.resolve('_service._tcp.example.com')# same but don't do dns request, load from cache if not expiredSRVResolverCached.resolve('_service._tcp.example.com')
Postgres SRV记录解析程序
从srv中提取postgres记录并检查主记录还是从记录。需要psycopg2
fromsrvresolver.postgres_resolverimportPostgresResolver# get random working slave recordPostgresResolver.get_slave('_postgresql._tcp.example.com',username,password)# get random working master recordPostgresResolver.get_master('_postgresql._tcp.example.com',username,password)