Advertisement
goebelmasse

Print HTTP-redirections for a given URI

Jan 14th, 2017
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.90 KB | None | 0 0
  1. #!/bin/sh
  2. ########################################################################
  3. #
  4. # location-cascade
  5. # $Id: location-cascade,v 1.1 2017/01/14 17:22:21 elias Exp $
  6. #
  7. # Give a list of HTTP redirections for a given URI.
  8. # Requires lynx.
  9. #
  10. ########################################################################
  11.  
  12. # User-agent
  13. # internet exploiter 10 for best results from spammy sites ;)
  14. UA='Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)'
  15.  
  16. httpcode=0
  17. uri=$1
  18. lasturi="$uri"
  19. while test "$httpcode" -lt 400 -o ! -z "$uri"
  20. do
  21.     set `lynx -useragent="$UA" -mime_header "$uri" 2>&1 |
  22.         sed -e '/^\s*$/q' |
  23.         awk '/^HTTP/ { code = $2 }
  24.                 /^Location/ { uri = $2; gsub("\\r", "", uri) }
  25.                 END { print code, uri }'`
  26.     lasturi="$uri"
  27.     httpcode="$1"
  28.     uri="$2"
  29.     echo "$httpcode\t$lasturi"
  30.     test "$httpcode" -eq 200 && break
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement