Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Java] RedirectScanner (Show real URL)

Featured Replies

Originally written by Deque of EZ.

 

 

this code snippet checks a given URL for redirects. I.e. if there is someone providing a shortened link with services like TinyURL can check the real URL here without visiting the site.

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
 
public class RedirectLocationScanner {
 
    public static void main(final String[] args) throws IOException {
        
        String urlStr = null;
 
        if (!(args.length == 1)) {
            Scanner scan = new Scanner(System.in);
            System.out.println("URL?");
            urlStr = scan.nextLine();
            scan.close();
        } else {
            urlStr = args[0];
        }
        
        if(!urlStr.startsWith("http://")){
            urlStr = "http://" + urlStr;
        }
        
        URL url = new URL(urlStr);
        HttpURLConnection.setFollowRedirects(false);
        String redirectLoc = url.openConnection().getHeaderField("Location");
        
        if(redirectLoc == null){
            System.out.println("No redirect.");
        } else {
            System.out.println("real URL: " + redirectLoc);
        }
    }
}

__________________________________________________________________

 

 

This code is an updated version, that also scans for target links in ad link services like adfly, adfoc and linkbucks.

import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Scanner;
 
 public class LinkScanner {
 
     private static final String[] adServiceStrings = { "adf.ly", "adfoc.us",
             "any.gs", "tinylinks,co", "linkbucks.com", "yyv.co", "miniurls.co",
             "qqc.co", "whackyvidz.com", "ultrafiles.net", "dyo.gs",
             "megaline.co", "uberpicz.com", "linkgalleries.net", "qvvo.com",
             "urlbeat.net", "seriousfiles.com", "zxxo.net", "ugalleries.net",
             "picturesetc.net" };
 
     private static final String USAGE = "java -jar scanner.jar <URL>";
 
     public static void main(String[] args) {
         try {
             if (args.length == 1) {
                 System.out.println("Target URL: ");
                 scanAndPrint(args[0]);
             } else if (args.length == 0) {
                 Scanner scan = new Scanner(System.in);
                 System.out.println("URL?");
                 String url = scan.nextLine();
                 scanAndPrint(url);
             } else {
                 System.out.println(USAGE);
             }
         } catch (IOException e) {
             System.err.println(e.getMessage());
         }
     }
 
     private static void scanAndPrint(String string) throws IOException {
         System.out.println("Scanning ...");
         String target = new LinkScanner().scan(string);
         if (target != null) {
             System.out.println("Target URL: ");
             System.out.println(target);
         } else {
             System.err.println("No target URL found");
         }
     }
 
     public String scan(String urlStr) throws IOException {
         if (!urlStr.startsWith("http://")) {
             urlStr = "http://" + urlStr;
         }
         URL url = new URL(urlStr);
         HttpURLConnection.setFollowRedirects(false);
 
         if (isAdServiceLink(urlStr)) {
             return handleAdLink(url);
         } else {
             return handleRedirect(url);
         }
 
     }
 
     private boolean isAdServiceLink(String urlStr) {
         for (String str : adServiceStrings) {
             if (urlStr.contains(str)) {
                 return true;
             }
         }
         return false;
     }
 
     private String handleRedirect(URL url) throws IOException {
         return url.openConnection().getHeaderField("Location");
     }
 
     private String handleAdLink(URL url) throws IOException {
         URLConnection urlc = url.openConnection();
         urlc.addRequestProperty("user-agent", "Firefox");
         BufferedReader in = null;
         try {
             in = new BufferedReader(
                     new InputStreamReader(urlc.getInputStream()));
             String line;
             while ((line = in.readLine()) != null) {
                 if (line.contains("var zzz =")) {
                     return extractADFlyURL(line);
                 }
                 if (line.contains("var click_url =")
                         && !line.contains("//var click_url =")) {
                     return extractADFocURL(line);
                 }
                 if (line.contains("Lbjs.TargetUrl =")) {
                     return extractLinkBucksURL(line);
                 }
             }
             throw new IOException("Unable to find target URL in link");
         } finally {
             if (in != null) {
                 in.close();
             }
         }
     }
 
     private String extractLinkBucksURL(String line) {
         String go = line.split("'")[1];
         return go;
     }
 
     private String extractADFocURL(String line) throws IOException {
         String go = line.split("\"")[1];
         return go;
     }
 
     private String extractADFlyURL(String line) throws IOException {
         String go = line.split("'")[1];
         String redirect = handleRedirect(new URL("http://adf.ly" + go));
         if (redirect == null) {
             return go;
         }
         return redirect;
     }
 }

Edited by Mac Dre

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.