批处理代码列出不ping的IP地址

发布于 2025-02-07 18:13:13 字数 747 浏览 2 评论 0原文

我正在使用以下代码从list.txt上的计算机名称列表列出IP地址,但是它们必须在列表中列出。如何编辑代码以显示这些不ping的IP地址?

@echo off

Echo Pinging list...

set ComputerList=list.txt

Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion

for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^|findstr Reply') do (
set IPadd=%%B
echo %%A,!IPadd:~0, -1!>>Results.csv
))

pause

list.txt包含以下内容:

”在此处输入图像描述”

结果

和 =“ https://i.sstatic.net/vi0fd.png” alt =“在此处输入图像说明”> ,

但它不会填充PCWindata103

I am using the code below to list ip addresses from a list of computer names on list.txt, but they have to be pinging to list. How can I edit the code to show these IP addressess that do not ping also?

@echo off

Echo Pinging list...

set ComputerList=list.txt

Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion

for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
for /f "tokens=3" %%B in ('ping -n 1 -l 1 %%A ^|findstr Reply') do (
set IPadd=%%B
echo %%A,!IPadd:~0, -1!>>Results.csv
))

pause

list.txt contains the following:

enter image description here

and

Results.csv will populate

enter image description here

but it will not populate IP address for PCWINDATA103 because it is not pinging but I know an IP exists

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

油焖大侠 2025-02-14 18:13:13

强制自定义输出如果findstr找不到回复(请注意“ Tokens = 3”):

...
for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
  for /f "tokens=3 delims=: " %%B in ('ping -4 -n 1 -l 1 %%A ^|findstr "Reply" ^|^|echo x x offline') do (
    echo %%A,%%B
  )
)

Force a custom output in case findstr doesn't find Reply (take care of "tokens=3"):

...
for /f "usebackq tokens=*" %%A in ("%ComputerList%") do (
  for /f "tokens=3 delims=: " %%B in ('ping -4 -n 1 -l 1 %%A ^|findstr "Reply" ^|^|echo x x offline') do (
    echo %%A,%%B
  )
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文