Une boucle avec la command PING

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alid0381
Posts: 28
Joined: 09 May 2012 10:37

Une boucle avec la command PING

#1 Post by alid0381 » 22 May 2012 10:11

Bonjour,

Voilà je cherche un script qui me permet de copier les adresses IP dans un fichier txt si ils répondent aux PI

Le BUT :

1- Les noms des sites : aaa.com bbb.net ccc.org ...
2- Nom du fichier test.txt
3- ET le résultat dans le formulaire ci-dessous :
xxx.xxx.xxx.xxx:aaa.com:
yyy.yyy.yyy.yyy:bbb.net:
zzz.zzz.zzz.zzz:ccc.org:
...
Merci.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Une boucle avec la command PING

#2 Post by aGerman » 22 May 2012 13:04

Sorry, but I don't understand French. I used the google translator to perceive your question. Please ask in English next time (like everybody does in that forum).

Not quite sure but I guess this is what you were talking about:

Code: Select all

@echo off &setlocal
>"test.txt" (
  for %%i in (
    aaa.com
    bbb.net
    ccc.org
  ) do (
    for /f "tokens=2 delims=[]" %%j in (
      'ping -n 1 %%i 2^>nul^|findstr "..*\[[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\]..*"'
    ) do echo %%j:%%i:
  )
)

Regards
aGerman

phillid
Posts: 109
Joined: 03 Apr 2010 20:27
Location: Wellington, New Zealand
Contact:

Re: Une boucle avec la command PING

#3 Post by phillid » 24 May 2012 01:07

alid0381, rien de personne parle francais sur le forum, mais je le parle un peu :P
Just to check, is this what you got from your translation, aGerman? (Google Translate is notorious for errors)

alid0381 wrote:Hello,
I'm trying to find a script that lets me to copy the IP addresses in a text file if they match PI

The Request:
1 - The names of the sites: ...
2 - Name of the text file: ...
3 - And the result in the layout just below:
xxx.xxx.xxx.xxx:aaa.com:
yyy.yyy.yyy.yyy:bbb.net:
zzz.zzz.zzz.zzz:ccc.org:

Thanks

Not sure what PI means..
alid0381 ! Est-ce que tu sais comment on dit 'PI' en anglais svp ? :)

Merci
Phillid

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Une boucle avec la command PING

#4 Post by aGerman » 24 May 2012 10:32

Thanks phillid. That's more or less what I translated. PI "could" be short for par intérim. I assume it means someting like "... if (ping was) successful".

Regards
aGerman

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Une boucle avec la command PING

#5 Post by alid0381 » 30 May 2012 07:13

hhhh...
Thanks to aGerman and phillid
Thanks to the team

There is a mistake : Not 'PI' But 'IP'

I do not speak English
I create a small program to write the IP addresses in a txt file in the form
xxx.xxx.xxx.xxx:aaa.com:

@echo off
mode 14,1&color 1e
set /a a = 254
set /a b = 254
set /a c = 254
set /a d = 250
:aa
IF %a% LEQ 255 (
IF %b% LEQ 255 (
IF %c% LEQ 255 (
IF %d% LEQ 255 (
echo %a%.%b%.%c%.%d%:e:>>"IP.txt"
set /a d = %d% + 1&goto aa
) ELSE (
set /a c =%c% + 1&set /a d = 250&goto aa
)
) ELSE (
set /a b =%b% + 1&set /a c = 254&goto aa
)
) ELSE (
set /a a =%a% + 1&set /a b = 254&goto aa
)
) ELSE (
EXIT
)
But the problème
...%d%:e:

how to create a batch file (*. bat) for each IP address to its site; if it exist!

Exemple
193.52.104.60:forum.ubuntu-fr.org:
74.125.230.196:google.com:
....

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Une boucle avec la command PING

#6 Post by foxidrive » 30 May 2012 07:42

This is untested: it tests the ping by the IP address, not the domain. Change ping %1 to ping %2 to test the domain name and DNS resolution

Code: Select all

@echo off
type nul>pass.txt
type nul>fail.txt
for /f "tokens=1,2 delims=:" %%a in (IPlist.txt) do call :ping %%a %%b
goto :EOF

:ping
echo testing %1:%2
ping %1|find /i "TTL=">nul
if %errorlevel%==0 >>pass.txt echo %1:%2&echo pass
if %errorlevel%==1 >>fail.txt echo %1:%2&echo        FAIL

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Une boucle avec la command PING

#7 Post by alid0381 » 30 May 2012 08:29

Thanks foxidrive

it's a good idea
But in the txte pass.txt There are :
google.com:

I changed in the line: "if %errorlevel%==0 >>pass.txt echo :%1:%2&echo pass" %1=>>:%1 ( means ) google.com: =>> :google.com:

What is the way to find in the txte pass.txt : 74.125.230.193:google.com:

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Une boucle avec la command PING

#8 Post by Fawers » 30 May 2012 09:44

The code he wrote is supposed to have both IP and domain name as parameters in order to echo them both.

foxidrive wrote:

Code: Select all

if %errorlevel%==0 >>pass.txt echo %1:%2&echo pass
if %errorlevel%==1 >>fail.txt echo %1:%2&echo        FAIL

%1 and %2 are CL parameters.

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Une boucle avec la command PING

#9 Post by alid0381 » 30 May 2012 11:08

Now
my colleague Fawers

I know the site, that in IPlist.txt
I also can get the IP from the command PING

All of these data supposed.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Une boucle avec la command PING

#10 Post by Fawers » 30 May 2012 13:47

Perhaps you didn't understand what I meant?
alid0381 wrote:Now
my colleague Fawers

I know the site, that in IPlist.txt
I also can get the IP from the command PING

All of these data supposed.


alid0381 wrote:But in the txte pass.txt There are :
google.com:

I changed in the line: "if %errorlevel%==0 >>pass.txt echo :%1:%2&echo pass" %1=>>:%1 ( means ) google.com: =>> :google.com:

What is the way to find in the txte pass.txt : 74.125.230.193:google.com:

Fawers wrote:The code he wrote is supposed to have both IP and domain name as parameters in order to echo them both.

foxidrive wrote:

Code: Select all

if %errorlevel%==0 >>pass.txt echo %1:%2&echo pass
if %errorlevel%==1 >>fail.txt echo %1:%2&echo        FAIL

%1 and %2 are CL parameters.


CL Parameters = command line parameters.
If you already have the IP list along with their respective domain names, you just have to run foxi's code with them.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Une boucle avec la command PING

#11 Post by foxidrive » 30 May 2012 18:08

alid0381,

Your request was poorly worded - I think what you want to do is to ping a set of domains and get the IP address and put them both in a text file like the following:
Is that right?

Exemple
193.52.104.60:forum.ubuntu-fr.org:
74.125.230.196:google.com:



Try this:

domainlist.txt contains
google.com:
telstra.com:



Code: Select all

@echo off
setlocal enabledelayedexpansion
for /f "delims=:" %%a in (domainlist.txt) do (
echo testing %%a
set domain=%%a:
for /f "tokens=2 delims=[]" %%b in ('ping -n 1 %%a ^|find "["') do set domain=%%b:!domain!
>>"IP.txt" echo !domain!
)

alid0381
Posts: 28
Joined: 09 May 2012 10:37

Re: Une boucle avec la command PING

#12 Post by alid0381 » 01 Jun 2012 04:07

How much you are wonderful and all the team

This is exactly what I want

Thank you Thank you Thank you...

Post Reply