简体   繁体   English

批处理脚本以获取网站ip地址?

[英]Batch script to get website ip address?

I'm trying to put together a batch file, that will ping a website, and assign its ip to a variable - I've searched around, but haven't really been able to put something together. 我正在尝试将一个批处理文件放在一起,它将对一个网站执行ping操作,并将其ip分配给一个变量-我已经搜索过,但实际上还无法将某些内容放在一起。 Can anyone shove me in the right direction. 谁能将我推向正确的方向。

Tim. 蒂姆

You could try the ping command. 您可以尝试ping命令。 The idea is to get the part between the [], of the ping output. 这个想法是获取ping输出的[]之间的部分。

@echo off
setlocal EnableDelayedExpansion
set myServer=google.de

for /f "tokens=1,2 delims=[]" %%a IN ('ping -n 1 !myServer!') DO (
 if "%%b" NEQ "" set ip=%%b
)
echo ip is %ip%

与上面的@jeb答案相同,但不使用EnableDelayedExpansion ,只需将“ www.google.com”替换为您喜欢的网站或%variablename%

for /f "tokens=2 delims=[]" %f in ('ping -4 -n 1 www.google.com ^|find /i "pinging"') do echo IP=%f

If all you want to do is look up the addresses, you might want to use nslookup rather than ping . 如果您只想查找地址,则可能要使用nslookup而不是ping Doing a search for "nslookup batch" gives you a bunch of results, including this one that looks like it should be fairly easy to adapt since it stores the result in variables. 这样做的“NSLOOKUP批”的搜索给你一堆的结果,其中包括一个看起来像它应该很容易适应,因为它存储结果的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM