Live Demo
You can see the live demo of the app here
Get Started
In order to get started we need to install a node.js dependency called as psl
which will actually extract the base url from the subdomain so kindly first of all initialize a node.js project
npm init -y
This will create the package.json file and then install psl
dependency like this
npm i psl
Now we want to create a index.js
file and copy paste the following code
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 |
const express = require('express') const bodyparser = require('body-parser') const psl = require('psl') const app = express() app.set('view engine','ejs') app.use(bodyparser.urlencoded({extended:false})) app.use(bodyparser.json()) const PORT = process.env.PORT || 4000 app.get('/',(req,res) => { res.render('extractbaseurl',{title:"Bulk Base URL Extractor From Subdomains"}) }) app.post('/getbaseurlwithhttp',(req,res) =>{ console.log(req.body.domain) var baseUrl = req.body.domain.protocol + "//" + req.body.domain.host + "/" + req.body.domain.pathname.split('/')[1]; res.json({ baseurl:baseUrl }) }) app.post('/getbaseurlwithouthttp',(req,res) =>{ var parsed = psl.parse(req.body.domain); console.log(parsed.domain) res.json({ baseurl:parsed.domain }) }) app.listen(PORT) |
Now we just need to make a AJAX
Request from the html file to this node.js post request to get the base url from the subdomain.
Now create a views
folder inside your root project and inside it you create extractbaseurl.ejs
file and copy paste the following code
views/extractbaseurl.ejs
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 129 130 131 132 133 |
<!DOCTYPE html> <html> <head> <title><%=title%></title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" /> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script> </head> <body> <div class="container"> <h1 class="text-center">Bulk Base URL Extractor From Subdomains</h1> <form id="form"> <div class="form-group"> <label for="domain">Enter Domains URL: (One Per Line)</label> <textarea class="form-control" rows="10" cols="20" id="domains" placeholder="Domain names" required ></textarea> </div> <label class="radio-inline" ><input type="radio" value="with" name="format" checked />(with http,https and www)</label > <label class="radio-inline" ><input type="radio" value="without" name="format" />(without http,https and www)</label > <div class="form-group"> <button id="button" class="btn btn-block btn-danger"> Extract Base URL's </button> </div> </form> <div> <div class="form-group"> <label for="output">Output:</label> <textarea class="form-control" name="" id="result" cols="30" rows="10" placeholder="Output" ></textarea> </div> </div> <div class="form-group"> <button id="copy" onclick="copytoclipboard()" class="btn btn-primary btn-block"> Copy to Clipboard </button> </div> </div> </body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/psl/1.8.0/psl.min.js"></script> <script> var domains, format; $("#form").submit(function (e) { e.preventDefault(); $("#result").empty(); $("#button").text("Extracting Base URL Please Wait"); $("#button").prop("disabled", "true"); format = $("input[name='format']:checked").val(); console.log(format); domains = $("#domains").val().split("\n"); console.log(domains); domains.forEach((domain) => { var domain; console.log(domain); if (format == "without") { domain = domain .replace(/^(?:https?:\/\/)?(?:www\.)?/i, "") .split("/")[0]; $.ajax({ method: "POST", url: "/getbaseurlwithouthttp", data: { domain: domain }, success: function (data) { console.log(data.baseurl); $("#button").text("Extract Base URL's"); document.getElementById("button").disabled = false; $("#result").append(`${data.baseurl}\n`); }, }); } else { var temp = document.createElement("a"); temp.href = domain; $("#result").append(`${temp.origin}\n`); $("#button").text("Extract Base URL's"); document.getElementById("button").disabled = false; } }); }); </script> <script> function copytoclipboard(){ var $temp = $("#result"); var brRegex = /<br\s*[\/]?>/gi; $temp.val($($temp).html().replace(brRegex, "\r\n")).select(); document.execCommand("copy"); Swal.fire( 'Good job!', 'Base URLs Successfully Copied', 'success' ) } </script> </html> |
Screenshots
DOWNLOAD SOURCE CODE