Windows提示充分利用文件的网页IP [英] WINDOWS PROMPT Getting IP of webpages from file

查看:136
本文介绍了Windows提示充分利用文件的网页IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到的网页,我会从txt文件提供的IP:
例如TXT文件如下:

I have to get IP of webpages that I'll deliver from txt file: for example txt file looks like:

google.com
yahoo.com
toyota.com
bmw.com
etc...

我必须要达到这样的

I'll have to get something like

81.177.116.172
11.127.114.122
etc..
or 
81.177.116.172 - google.com
11.127.114.122 - yahoo.com

我知道,我可以使用

I know that I can use

ping websiteurl.com > ping.txt

但我要检查像2000页。请指点如何做到这一点的最快方法,以及如何从txt文件提供行参数来ping通。谢谢

but i want to check like 2000 pages. Please advice how to do it the fastest way, and how to deliver line from txt file as parameter to ping. Thanks

推荐答案

接下来的更新注释 code段是在我原来比code快回答:

Next updated and commented code snippet is faster than code in my original answer:

@ECHO OFF
SETLOCAL enableextensions disabledelayedexpansion

set "_format=%~1"                   use for output ''beautifying''
if defined _format (
  echo        hostname OP IPv4_address    explanation
  echo        -------- -- ------------    -----------
)
set "_file=files\30852528.txt"      change to fit your circumstances

for /F "usebackq delims=" %%i in ("%_file%") do (
  set "_host=%%i"                   remember input line 

  for /F "tokens=1 delims==" %%G in ('set ___ping 2^>NUL') do set "%%G="

  set /A "_line=0" 
  for /F "delims=" %%G in ('ping -a -4 -n 1 %%i') do (
    set /A "_line+=1"
    call set "___ping%%_line%%=%%G" remember ping output to an array-like variable
  )
  REM   rem debug output in next two lines
  REM   echo(
  REM   for /F "tokens=1* delims==" %%G in ('set ___ping 2^>NUL') do echo(%%H
  call :pings
) 
ENDLOCAL
goto :eof

:pings
  set "_operator=??"
  set "_hostIPno=%_host%"
  set "_hostName=%_host%"
  set "_auxiliar="
  set "_explains=Unknown reason"    default values set

  set "_string=Ping request could not find host"
  for /F "delims=" %%G in ('set ___ping^|findstr /i /C:"%_string%"') do (
      set "_operator=##"
      set "_explains=%_string%"     ping request could not find host
      goto :pingsDone
  )

  set "_string==Pinging"
  for /F "tokens=1-4 delims==[] " %%G in ('set ___ping^|findstr /i /C:"%_string%"') do (
      echo("%%J"|findstr /r "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*">NUL
      if errorlevel 1 (
          set "_auxiliar=%%H %%I"
      ) else (
          set "_auxiliar=%%H %%I [%%J]"
          set "_hostIPno=%%J"
          set "_hostName=%%I"       address to hostname resolved
      )
  )

  set "_string=Destination host unreachable"
  for /F "tokens=1* delims==" %%G in ('set ___ping^|findstr /i /C:"%_string%"') do (
      set "_explains=%%H"
      set "_operator=?="            destination host unreachable
  )

  set "_string=Request timed out"
  for /F "tokens=1* delims==" %%G in ('set ___ping^|findstr /i /C:"%_string%"') do (
      set "_explains=%_auxiliar%: %%H"
      set "_operator==?"            request timed out
  )

  set "_string=TTL="
  for /F "tokens=1* delims==" %%G in ('set ___ping^|findstr /i "%_string%"') do (
      set "_explains=%%H"
      set "_operator==="            ping request successful
  )
:pingsDone
  rem basic formatting: output to columns only for demonstration at StackOverflow
  if defined _format (
      set "_hostName=               %_hostName%"
      set "_hostIPno=%_hostIPno%               "
      set "_explains= %_explains%"
  ) else set "_explains="
  if defined _format (
      set "_hostName=%_hostName:~-15%"
      set "_hostIPno=%_hostIPno:~0,15%"
  )

  rem output with delayed expansion enabled:
  SETLOCAL enabledelayedexpansion
    echo(!_hostName! !_operator! !_hostIPno!!_explains!
  ENDLOCAL
goto :eof

数据

d:\bat> type "files\30852528.txt"|findstr /V "^;"
foo.bar
google.com
77.75.79.53
192.168.1.1
192.168.1.12
bmw.com
160.46.244.131

输出(从打开 CMD 窗口中运行):

Output (run from an open cmd window):

d:\bat> so\30852528.bat
foo.bar ## foo.bar
google.com == 216.58.209.206
www.seznam.cz == 77.75.79.53
192.168.1.1 == 192.168.1.1
192.168.1.12 ?= 192.168.1.12
bmw.com =? 160.46.244.131
origin.bmw.com =? 160.46.244.131

美化的输出

Beautified output:

d:\bat> so\30852528.bat 1
       hostname OP IPv4_address    explanation
       -------- -- ------------    -----------
        foo.bar ## foo.bar         Ping request could not find host
     google.com == 216.58.209.206  Reply from 216.58.209.206: bytes=32 time=24ms TTL=56
  www.seznam.cz == 77.75.79.53     Reply from 77.75.79.53: bytes=32 time=10ms TTL=248
    192.168.1.1 == 192.168.1.1     Reply from 192.168.1.1: bytes=32 time<1ms TTL=64
   192.168.1.12 ?= 192.168.1.12    Reply from 192.168.1.100: Destination host unreachable.
        bmw.com =? 160.46.244.131  Pinging bmw.com [160.46.244.131]: Request timed out.
 origin.bmw.com =? 160.46.244.131  Pinging origin.bmw.com [160.46.244.131]: Request timed out.

这篇关于Windows提示充分利用文件的网页IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆