python - 获取远程主机列表的时间
问题描述
我需要从通过 VPN 连接的远程主机列表中获取时间。
该列表位于一个 txt 文件中,我希望将输出放在另一个文件中,其中包含 IP 和在远程机器上注册的时间。
我用这个windows powershell代码解决了:
foreach($line in [System.IO.File]::ReadLines("percorso_del_file.txt"))
{
net time \\$line
}
解决方案
类似的东西。你会得到当地时间。
[System.IO.File]::ReadLines("percorso_del_file.txt") |
Foreach-Object {
$local:computer = $_
try {
$local:wmi_os = Get-WmiObject -Class 'win32_operatingsystem' -Property @('localdatetime','__SERVER') -ComputerName $local:computer -ErrorAction Stop
$local:o = New-Object -TypeName 'PSObject' -Property @{
ComputerName = $local:wmi_os.'__SERVER';
Time = $local:wmi_os.ConvertToDateTime($local:wmi_os.localdatetime)
}
} catch {
$local:o = New-Object -TypeName 'PSObject' -Property @{
ComputerName = $local:computer
Time = [DateTime]::MinValue
}
}
return $local:o
} |
Export-Csv -LiteralPath 'c:\report.csv' -Encoding UTF32 -Delimiter "`t" -NoTypeInformation
推荐阅读
- python - 有没有一种方法可以帮助我使用 python selenium 为 Facebook 页面点赞
- java - 使用 Twitter 搜索 API 时出现 400 错误代码
- javascript - request-promise-native 的替代方案
- c - 移位并确保最后两位数字在 C 中为 10
- macos - 如何报告 AppKit 错误我无法重现但有几十个报告 (NSControlTrackMouse)
- sql - SQL 排列查询
- javascript - 有什么方法可以循环遍历这些数字:-1 0, 1 0, 0 -1, 0 1
- apache-kafka - Kafka Connect:没有为连接器创建任务
- c# - 在 XmlNode 数组中按名称查找值
- python - 我应该在打开 jupyter notebook 之前使用“conda init”吗?