Last active
December 15, 2015 07:59
-
-
Save KINGSABRI/5227705 to your computer and use it in GitHub Desktop.
url-extract, just a simple script to check if url is redirecting to another or not! it supports proxy authentication too.
You can use it to extracting shorten urls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
def fetch(uri_str, limit = 10) | |
#==[ Proxy settings ]==# | |
proxy_host = "127.0.0.1" | |
proxy_port = 8000 | |
proxy_user = "" | |
proxy_pass = "" | |
raise ArgumentError, 'too many HTTP redirects' if limit == 0 | |
response = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).get_response(URI(uri_str)) | |
case response | |
when Net::HTTPSuccess then | |
warn "[-] #{uri_str} No redirection." | |
when Net::HTTPRedirection then | |
location = response['location'] | |
warn "[+] #{uri_str}\n |---> #{location}\n" | |
else | |
response.value | |
end | |
end | |
fetch('http://t.co/axj2ak7tSC') # Twitter shorten to google shorten 2 level redirect | |
fetch("http://goo.gl/uYHy4") | |
fetch("http://alturl.com/phy9e") | |
fetch("http://tiny.cc/wseeuw") | |
fetch("http://king-sabri.net") | |
### Todo ,, support muti redirection levels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment