python 操作windows DNS

本文提供了Windows环境下WinRM服务的基础配置教程,包括启用服务、设置认证方式及加密等,并介绍了如何调整性能参数来优化WinRM服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在windows平台上启用winrm服务
winrm service 默认都是未启用的状态,先查看状态;如无返回信息,则是没有启动;

winrm enumerate winrm/config/listener

针对winrm service 进行基础配置:

winrm quickconfig

查看winrm service listener:

winrm e winrm/config/listener

为winrm service 配置auth:

winrm set winrm/config/service/auth @{Basic="true"}

为winrm service 配置加密方式为允许非加密:

winrm set winrm/config/service @{AllowUnencrypted="true"}

一些比较常用的命令

执行以下命令能够以每组多达50个实例的速度获取实例。

winrm set winrm/config @{MaxBatchItems="50"}

此外,通过增大分配的最大封包大小和超时设置,也可以提高性能。

winrm set winrm/config @{MaxEnvelopeSizekb="150"}
winrm set winrm/config @{MaxTimeoutms ="60000"}

下面列出了其他可选的WinRM配置命令,以便您参考。要获取当前的WinRM配置设置,请执行以下命令:

winrm g winrm/config

默认情况下,客户端计算机要求对网络流量加密。要允许客户端计算机请求未加密流量,请执行以下命令:

winrm s winrm/config/Client @{AllowUnencrypted="true"}

TrustedHosts 是一个数组,用于指定可信的远程计算机的列表。同一工作组中的其他计算机或不同域中的计算机均应添加到此列表中。

注意:TrustedHosts 列表中的计算机未经过身份验证。
执行以下命令可将所有计算机都纳入TrustedHosts。

winrm s winrm/config/Client @{TrustedHosts="*"}

基本身份验证是以明文形式将用户名和密码发送给服务器或代理的方案。这是最不安全的身份验证方法。默认值为True。
执行以下命令可将客户端计算机设置为使用基本身份验证:

winrm s winrm/config/Client/Auth @{Basic="true"}

 

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import winrm
import sys
import argparse

#define the target host
#host=raw_input("input the hostname :")
#username=raw_input("username :")
#passwd=raw_input("passwd :")

# start the connection session
#s = winrm.Session('http://' + host + ':5985/wsman' ,auth=(username,passwd))
s=winrm.Session('http://IP:5985/wsman',auth=('user','password'))
def _runCommand(comm):
r = s.run_cmd(comm)
print (r.std_out)
sys.exit()

while 1:
comm = 'dnscmd . /zoneprint abc.com.cn | findstr /i "3600 A"' #查询
# dnscmd . /RecordAdd abc.com.cn xxxx A 10.164.64.200 #添加xxx.abc.com.cn和对应IP
    _runCommand(comm)







import dns.resolver


def dnsresolver(dname,cate):   # dnsresolver('home.cathay-ins.com.cn','A')
    if cate == 'A':
        A = dns.resolver.query(dname,cate)   # 指定查看类型为A记录
        for i in A.response.answer:  # 通过response.answer方法获取查询回应信息
            for j in i.items:        # 遍历回应信息
                return j.address
    if cate =='CNAME':
        cname = dns.resolver.query(dname,cate)
        for i in cname.response.answer:  # 结果将回应cname后的目标域名
            for j in i.items:
                return j.to_text()

# try:
#     a = dnsresolver('home1.abc.com.cn','A')
#     print(a)
# except Exception as e:
#     print(e)

#comm = 'dnscmd . /EnumRecords abc.com.cn home'
#a = inwin(comm)
#print(a)
# if 'successfully' in a:
#     print('1')
# else:
#     print('2')



def checkdns(name):
    comm = 'dnscmd . /EnumRecords abc.com.cn %s'%name
    info = inwin(comm)
    if 'successfully' in info:
        return True
    else:

 

转载于:https://www.cnblogs.com/linhankbl/p/9149421.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值