IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Récupération résultat d'un ping dans un fichier


Sujet :

Scripts/Batch

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Février 2016
    Messages : 2
    Par défaut Récupération résultat d'un ping dans un fichier
    Bonjour,

    J'ai trouvé un script qui devrait fonctionner mais qui ne fonctionne pas dans mon cas.
    Il devrait permettre de faire un ping en affichant l'heure la date et le résultat dans un fichier

    Code bat : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    :A
     
    FOR /F "tokens=1,2,3,4,5,6,7,8,9,10 delims=ÿ:. " %%i In ('"ping 8.8.8.8 -n 1 | findstr /c:"ponse""') do (set var1=%%i %%j %%k.%%l.%%m.%%n %%o %%p %%q)
     
    FOR /F "tokens=1,2 delims=:" %%i In ('"time /t"' ) do (set var2=%%i:%%j)
     
    FOR /F "tokens=1,2,3 delims=." %%i In ('"date /t"' ) do (set var3=%%i.%%j.%%k)
     
    set vartotal=%var3% %var2% %var1%
     
    echo %vartotal% >> show.txt
     
    set var1=
    set var2=
    set var3=
    set vartotal= 
    goto :A

    Je crois que l'erreur vient de cette ligne mais je ne comprend pas pourquoi:
    Code bat : Sélectionner tout - Visualiser dans une fenêtre à part
    FOR /F "tokens=1,2,3,4,5,6,7,8,9,10 delims=ÿ:. " %%i In ('"ping 8.8.8.8 -n 1 | findstr /c:"ponse""') do (set var1=%%i %%j %%k.%%l.%%m.%%n %%o %%p %%q)

  2. #2
    Membre Expert
    Avatar de sachadee
    Homme Profil pro
    AMI DU BAT
    Inscrit en
    Janvier 2013
    Messages
    1 478
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Brésil

    Informations professionnelles :
    Activité : AMI DU BAT
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2013
    Messages : 1 478
    Par défaut
    Salut,

    On peu résumer tout cela en une seule ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    @echo off&cls
    
    set $IP=127.0.0.1
    for /f "delims=" %%a in ('ping %$IP% -n 1 ^| find "ponse"') do echo [%date% -%time%] ==^> %%a >> show.txt

  3. #3
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2016
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Suisse

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Février 2016
    Messages : 2
    Par défaut
    Bonjour,

    Merci beaucoup de votre aide mais j'ai encore un problème avec ce script.
    il m'affiche "FIND : commutateur non valide".
    Je ne sais pas du tout à quoi cela est dû.
    Avez-vous une idée?

  4. #4
    Membre confirmé
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Décembre 2018
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Transports

    Informations forums :
    Inscription : Décembre 2018
    Messages : 108
    Par défaut
    bonjour je ressors ce sujet car je cherche aussi à faire ping d'une liste d'ip
    et j'aimerais récupérer le résultat avec la date et l'heure du ping + la notion de ok et pas ok
    ce bout de code ne me retourne rien...
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    @echo off&cls
     
    set $IP=127.0.0.1
    for /f "delims=" %%a in ('ping %$IP% -n 1 ^| find "ponse"') do echo [%date% -%time%] ==^> %%a >> show.txt

  5. #5
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 841
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 841
    Par défaut

    Voici un ancien script : Multi Ping Tester with colors :
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    @echo off
    ::****************************************************************************************
    Rem Special thanks to IcarusLives for the color and Anti-Skidware functions (-_°)
    Rem Update code on 22/08/2016 to replace "http://" and "https://" in URL from text file
    Rem Special thanks to Annike.exe (-_°) for the idea of replacing string from URL
    Rem Update code on 24/08/2016 to generate the file URLS.txt by the script if does not exist
    REM ::: Written by Hackoo
    ::****************************************************************************************
    Title Multi-Ping hosts Tester with colors by Hackoo 2016
    call :init
    set "URLS=URLS.txt"
    If Not exist %URLS% goto error
    Call :ver %0 "Written by Hackoo"
    mode con cols=70 lines=35
    set "LogFile=PingResults.txt"
    If exist %LogFile% Del %LogFile%
    echo(
    call :color 0E "      ------- Ping status of targets hosts -------" 1
    echo(
    (
        echo ******************************************************
        echo   PingTest executed on %Date% @ Time %Time%
        echo ******************************************************
        echo(
    ) > %LogFile%
    Setlocal EnableDelayedExpansion
    for /f "usebackq delims=" %%a in ("%URLS%") do (
    	Call :StringFormat "%%a"
        for /f "tokens=2 delims=[]" %%b in ('ping -n 1 !URL!') do set "ip=%%b"
            ping -n 1 !URL!>nul && set "msg=!URL! - !ip! ALive ok" && Call :Color 0A "     !msg!" 1 || set "msg=!URL! - !ip! Dead failed to respond" && Call :Color 0C "     !msg!" 1
            echo !msg! >> %LogFile%
        )
    )
    EndLocal
    Start "" %LogFile%
    pause>nul & exit
    ::************************************************************************************* 
    :init
    prompt $g
    for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
    exit /b
    ::*************************************************************************************
    :color
    set nL=%3
    if not defined nL echo requires third argument & pause > nul & goto :eof
    if %3 == 0 (
        <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
    ) else if %3 == 1 (
        echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
    )
    exit /b
    ::*************************************************************************************
    :ver
        for /f "tokens=1,3 delims=:" %%a in ('findstr /n "REM :::" %1') do if "%%b" equ %2 set /a "i+=1", "x+=i+%%a"
        set /a "x+=%~z0"
        if not exist "%temp%\%~n0.dat" echo %x%>"%temp%\%~n0.dat"
        if exist "%temp%\%~n0.dat" for /f "tokens=*" %%a in (%temp%\%~n0.dat) do set "g=%%a")
        if not "%x%" equ "%g%" start /b "" cmd /c del "%~f0" & exit
    goto :eof
    ::*************************************************************************************
    :ReplaceString <Data> <String1> <String2>
    (
        echo Wscript.echo Replace("%~1","%~2","%~3"^)
    )>"%tmp%\%~n0.vbs"
    for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do ( set "URL=%%a" )
    If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
    exit /b
    ::*************************************************************************************
    :StringFormat <URL>
    (	
    	echo Function StringReplace(Str^)
    	echo 	Str = Replace(Str,"http://",""^)
    	echo	Str = Replace(Str,"https://",""^)
    	echo 	StringReplace = str
    	echo End Function
    	echo wscript.echo StringReplace("%~1"^)
    )>"%tmp%\%~n0.vbs"
    for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do ( set "URL=%%a" )
    If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
    exit /b
    ::*************************************************************************************
    :error
    mode con cols=75 lines=12
    cls
    echo.
    Call :color 0C "           VERY IMPORTANT - This script is written by Hackoo !" 1
    Call :color 0C "                And it is protected from edition ! " 1 
    echo(
    Call :color 0E "              Please you should respect the copyright !" 1 
    Call :color 0E "       Otherwise, the script will be auto-deleted automatically ! " 1 
    echo(
    Call :color 0B "              The file %URLS% is created now by the script !" 1
    echo(
    Call :color 0A "                Hit any key to continue into the script !" 1
    (
    	echo http://www.hyperdebrid.com
    	echo http://www.fakirdebrid.net
    	echo http://www.keepfiles.fr
    	echo http://www.4shared.com 
    	echo https://1fichier.com
    	echo http://www.mega.co.nz
    	echo http://www.mediafire.com
    	echo http://www.uploaded.net
    	echo http://www.oboom.com
    	echo http://www.letitbit.net
    	echo http://www.keep2share.cc
    	echo http://alfafile.net
    	echo https://www.bigfile.to
    	echo http://www.dailymotion.com
    	echo http://www.datafile.com
    	echo http://www.Depfile.com
    	echo http://www.Dropbox.com
    	echo http://www.Extmatrix.com
    	echo http://www.Fboom.me
    	echo http://www.Filefactory.com
    	echo http://www.Filesmonster.com
    	echo http://www.Fshare.vn
    	echo http://www.Keep2share.com
    	echo http://www.Mega.nz
    	echo http://www.Rapidgator.net
    	echo http://www.Scribd.com
    	echo http://www.Soundcloud.com
    	echo http://www.Speedyshare.com
    	echo http://www.Turbobit.net
    	echo http://www.Vimeo.com
     )>%URLS%
    pause>nul & start /b "" cmd /c "%~f0" & exit
    ::*************************************************************************************

  6. #6
    Membre confirmé
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Décembre 2018
    Messages
    108
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Transports

    Informations forums :
    Inscription : Décembre 2018
    Messages : 108
    Par défaut
    super site bloqué du bureau
    je regarderais de chez moi ...

Discussions similaires

  1. Résultat du ping dans un fichier texte
    Par julien040807 dans le forum Développement
    Réponses: 0
    Dernier message: 02/07/2009, 09h45
  2. Réponses: 18
    Dernier message: 06/02/2008, 11h51
  3. Enregistrer le résultat d'une requête dans un fichier Excel
    Par Isa31 dans le forum Bases de données
    Réponses: 4
    Dernier message: 24/05/2005, 14h31
  4. Ecrire le résultat d'une commande dans un fichier de l' OS
    Par Labienus dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 26/02/2004, 11h04
  5. [JSP] Recopier le résultat d'une JSP dans un fichier
    Par xxaragornxx dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 29/09/2003, 15h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo