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 :

Vérifier si un site internet est valide et si la page ne redirige pas vers une autre page [Batch]


Sujet :

Scripts/Batch

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut Vérifier si un site internet est valide et si la page ne redirige pas vers une autre page
    Bonjour,

    Je réalise un script en batch qui génère des liens imgur puis qui les vérifies pour voir si ils existent.
    J'ai trouvé ce script powershell qui vérifie si un site est valide :

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    set url="https://i.imgur.com/%A%%B%%C%%D%%E%%F%%G%.jpeg"
    Powershell -ExecutionPolicy Bypass -Command Invoke-Command -ScriptBlock {try{invoke-webrequest $args[0] -DisableKeepAlive -UseBasicParsing -Method head^|Out-Null;exit 0}catch{exit 1}} -ArgumentList %url% &&echo Valid||echo Non valid

    Une image imgur est composé de 7 lettres ou chiffres, exemple : "i.imgur.com/AD3MbBi.jpeg" donc le script vérifie si la page existe.
    Tous les liens ne peuvent pas êtres valides donc le script regarde si la page de l'image existe.
    Mais le problème est que tous les liens sont valide car si une image n'existe pas, imgur redirige vers la page "i.imgur.com/removed.png"

    Donc comment faire pour check si imgur ne redirige pas vers une autre page ou directement si l'image n'existe pas ?

    J'ai essayé d'expliqué mon problème le plus simplement possible si vous avez des questions n'hésitez pas

    Merci

  2. #2
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut Get_Status_CURL.bat

    Si vous êtes sur un windows 10 par example, vous pouvez tester avec curl afin d'obtenir les status codes, donc pour la redirection normalement, il va afficher 302 ou bien 301

    Get_Status_CURL.bat
    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
    @echo off
    Title Get Status Codes from URL using the command line CURL
     
    Set "ONLINE=%~dp0ONLINE.txt" 
    If Exist "%ONLINE%" Del "%ONLINE%"
    Set "OFFLINE=%~dp0OFFLINE.txt" 
    If Exist "%OFFLINE%" Del "%OFFLINE%"
     
    Set URLS="https://i.imgur.com/xgZZXLi.jpeg" "https://i.imgur.com/xhelllooi.jpeg" "https://i.imgur.com/BIDON.jpeg" "https://i.imgur.com/nimpotrequoi.jpeg" ^
    ^ "https://www.youtube.com" "https://www.youtube.com/channel/example" ^
    ^ "https://www.tiktok.com" "https://www.facebook.com" "https://www.reddit.com" ^
    ^ "https://www.yahoo.com" "https://pastebin.com" "https://www.twitter.com" "https://twitter.com/" ^
    ^ "https://help4windows.com/windows_8_shell32_dll.shtml" "https://help4windows.com" "https://instant-hack.to" ^
    ^ "https://hackforums.net/" "https://www.ultimate-guitar.com/explore" " https://accounts.snapchat.com" ^
    ^ "https://stackoverflow.com" "https://superuser.com" "https://codereview.stackexchange.com" "https://security.stackexchange.com" "https://serverfault.com" ^
    ^ "https://ss64.com/" "https://www.dostips.com/" "https://batch.xoo.it"
     
    echo/
    SetLocal EnableDelayedExpansion
    @for %%a in (%URLS%) do (
    	Call :Get_Status "%%~a" 
    	If [!httpCode!] EQU [200] (
    		Call :PSColor "[!Time!] [!httpcode!] [!Description!] [%%~a]" DarkGreen \n
    		echo [!Time!] [!httpcode!] [!Description!] [%%~a]>>"%ONLINE%"
    	) Else (
    		Call :PSColor "[!Time!] [!httpcode!] [!Description!] [%%~a]" DarkRed \n
    		echo [!Time!] [!httpcode!] [!Description!] [%%~a]>>"%OFFLINE%"
    	)
    )
    EndLocal & Pause & EXIT /B
    REM -----------------------------------------------------------------------------------
    :Get_Status <url> <httpCode>
    @for /f "tokens=*" %%a in (
    	'curl -sI -o nul -w "%%{http_code}" "%~1"'
    ) do (
    	Set "httpCode=%%a"
    	If [!httpcode!] EQU [503] (set "Description=Service Unavailable")
    	If [!httpcode!] EQU [500] (set "Description=Internal Server Error")
    	If [!httpcode!] EQU [404] (set "Description=Not Found OFFLINE")
    	If [!httpcode!] EQU [403] (set "Description=Forbidden Access Denied")
    	If [!httpcode!] EQU [302] (set "Description=Temporary Redirect")
    	If [!httpcode!] EQU [301] (set "Description=Redirect and Moved Permanently")
    	If [!httpcode!] EQU [200] (set "Description=OK ONLINE")
    	If [!httpcode!] EQU [000] (set "Description=TIMEOUT Server Rejected the Request")
    )
    Exit /B
    REM ----------------------------------------------------------------------------------
    :PSColor <String> <Color> <NewLine>
    If /I [%3] EQU [\n] (
    	Powershell Write-Host "`0%~1" -ForegroundColor %2
    ) Else (
    	Powershell Write-Host "`0%~1" -ForegroundColor %2 -NoNewLine
    )
    Exit /B
    REM -----------------------------------------------------------------------------------
    REM https://www.reddit.com/r/Batch/comments/vl9drp/comment/idumo9g/?utm_source=share&utm_medium=web2x&context=3

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Bonjour,

    Si tu es sur Windows 10, tu pourrais utiliser la commande curl pour tester le code http de retour :
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    curl -sI "https://i.imgur.com/AD3MbBi.jpeg" | findstr "HTTP"
    Si l'image existe le code de retour sera 200, sinon ce sera 302 ou autre.
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    curl -sI "https://i.imgur.com/AD3MbBi.jpeg" | findstr "HTTP" | findstr "200" && echo l'image existe

  4. #4
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    C'est normal que dans le fichier OFFLINE.txt j'ai que des erreurs 000 TIMEOUT Server Rejected the Request
    Genre comme ça : [23:28:47,25] [000] [TIMEOUT Server Rejected the Request] [https://i.imgur.com/xgZZXLi.jpeg]

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

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut


    Code BATCH : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    @echo off
    set urls="https://i.imgur.com/xgZZXLi.jpeg" "https://i.imgur.com/AD3MbBi.jpeg" "https://i.imgur.com/AD3MbHelloBi.jpeg"
    @for %%a in (%urls%) do (
        curl -sI %%a | findstr "200">nul && echo l'image %%a existe || echo l'image %%a n'existe pas
    )
    pause
    exit /b

  6. #6
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Salut,
    Dans la fenêtre dos, c'est écris que toutes les images n'existent pas :

    l'image "https://i.imgur.com/xgZZXLi.jpeg" n'existe pas
    l'image "https://i.imgur.com/AD3MbBi.jpeg" n'existe pas
    l'image "https://i.imgur.com/AD3MbHelloBi.jpeg" n'existe pas
    Alors que les deux premières existent, si je remplace une url par "https://youtube.com" par exemple, ça me dit que l'image n'existe pas alors que youtube.com existe...

    Ps: je suis bien sous windows 10
    Merci

  7. #7
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Citation Envoyé par barnabe0057 Voir le message
    Bonjour,

    Si tu es sur Windows 10, tu pourrais utiliser la commande curl pour tester le code http de retour :
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    curl -sI "https://i.imgur.com/AD3MbBi.jpeg" | findstr "HTTP"
    Si l'image existe le code de retour sera 200, sinon ce sera 302 ou autre.
    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    curl -sI "https://i.imgur.com/AD3MbBi.jpeg" | findstr "HTTP" | findstr "200" && echo l'image existe
    Et ça ne marche pas aussi pour moi, j'ai aucun message dans le fenêtre dos.

  8. #8
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Si tu n'as aucun message c'est que le code retour était différent de 200, donc l'image n'existe pas.

  9. #9
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Oui mais même si l'image existe, j'ai aucun message...

  10. #10
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Alors il faudrait analyser ce que renvoie curl sans les findstr.

  11. #11
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 185
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 185
    Points : 5 757
    Points
    5 757
    Par défaut
    Je n'aime pas trop cela mais bon si ça peu te dépanner

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
     
    set urls="https://i.imgur.com/xgZZXLi.jpeg" "https://i.imgur.com/AD3MbBi.jpeg" "https://i.imgur.com/AD3MbHelloBi.jpeg"
    for %%a in (%urls%) do (
    	Powershell -ExecutionPolicy Bypass -Command Invoke-Command -ScriptBlock {$ProgressPreference = 'SilentlyContinue';try{exit ^(Invoke-WebRequest -uri "%%~a" -DisableKeepAlive -UseBasicParsing -Method head^).StatusCode}catch{exit 9999}}
    	if !ERRORLEVEL! EQU 200 (echo SUCCESS : %%~a) else (echo ERROR : %%~a)
    )
     
    pause

  12. #12
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Citation Envoyé par ericlm128 Voir le message
    Je n'aime pas trop cela mais bon si ça peu te dépanner

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    @echo off
    SETLOCAL ENABLEDELAYEDEXPANSION
     
    set urls="https://i.imgur.com/xgZZXLi.jpeg" "https://i.imgur.com/AD3MbBi.jpeg" "https://i.imgur.com/AD3MbHelloBi.jpeg"
    for %%a in (%urls%) do (
    	Powershell -ExecutionPolicy Bypass -Command Invoke-Command -ScriptBlock {$ProgressPreference = 'SilentlyContinue';try{exit ^(Invoke-WebRequest -uri "%%~a" -DisableKeepAlive -UseBasicParsing -Method head^).StatusCode}catch{exit 9999}}
    	if !ERRORLEVEL! EQU 200 (echo SUCCESS : %%~a) else (echo ERROR : %%~a)
    )
     
    pause
    ça ne marche qu'avec les liens qui renvoient vers la page d'erreur 404 mais pas pour le liens qui renvoient vers la page "https://i.imgur.com/removed.png"

    Quand ça redirige vers "https://i.imgur.com/removed.png" il y a quand même une requête http 200 alors que l'image n'existe pas.

  13. #13
    Expert éminent
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 839
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 839
    Points : 9 222
    Points
    9 222
    Par défaut
    Citation Envoyé par steever38 Voir le message
    ça ne marche qu'avec les liens qui renvoient vers la page d'erreur 404 mais pas pour le liens qui renvoient vers la page "https://i.imgur.com/removed.png"

    Quand ça redirige vers "https://i.imgur.com/removed.png" il y a quand même une requête http 200 alors que l'image n'existe pas.

    C'est quoi votre système d'exploitation ?
    Postez-nous les liens que vous avez réellement tester dans un fichier texte et dans la pièce-jointe.

  14. #14
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Citation Envoyé par hackoofr Voir le message

    C'est quoi votre système d'exploitation ?
    Postez-nous les liens que vous avez réellement tester dans un fichier texte et dans la pièce-jointe.
    Je suis sons windows 10 professionnel version 20H2, ma session dispose des privilèges administrateurs.
    Et oui, je mets bien les urls a tester dans la variable "urls"

  15. #15
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 185
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 185
    Points : 5 757
    Points
    5 757
    Par défaut
    Citation Envoyé par steever38 Voir le message
    ça ne marche qu'avec les liens qui renvoient vers la page d'erreur 404 mais pas pour le liens qui renvoient vers la page "https://i.imgur.com/removed.png"

    Quand ça redirige vers "https://i.imgur.com/removed.png" il y a quand même une requête http 200 alors que l'image n'existe pas.
    Un exemple de lien STP ?

  16. #16
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2021
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Avril 2021
    Messages : 49
    Points : 56
    Points
    56
    Par défaut
    Je peux fermer ce sujet, j'ai trouvé une autre méthode, ça télecharge toutes les images et supprime celle qui font 503 octets

  17. #17
    Expert confirmé

    Homme Profil pro
    Responsable déploiement (SCCM, InTune, GPO)
    Inscrit en
    Juillet 2014
    Messages
    3 185
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable déploiement (SCCM, InTune, GPO)
    Secteur : Transports

    Informations forums :
    Inscription : Juillet 2014
    Messages : 3 185
    Points : 5 757
    Points
    5 757
    Par défaut
    Tant pis

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 10/09/2019, 13h23
  2. Mon site internet est-il legale ?
    Par lesckrank dans le forum Général Conception Web
    Réponses: 3
    Dernier message: 20/08/2014, 23h57
  3. Tester si une connection internet est valide
    Par blondelle dans le forum C++Builder
    Réponses: 3
    Dernier message: 19/05/2008, 18h48

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