Last active
August 29, 2015 14:22
-
-
Save concerned3rdparty/b68114ec802cfc93a29b to your computer and use it in GitHub Desktop.
Random Url Response examination
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
package pack | |
import java.net.{HttpURLConnection, URL} | |
import scala.collection.immutable._ | |
object RandomUrlResponse extends App{ | |
var urlStatusMap = SortedMap[String,Int]() | |
val url = "http://www.randomwebsite.com/cgi-bin/random.pl" | |
var con : HttpURLConnection = _ | |
var locHeader: String = _ | |
var resCode: Int = _ | |
var domainName: String = _ | |
/*Test prefix removal | |
println("https://www.ersan.com.tr".replaceFirst("^(https?://)?(www.)?", "")) | |
println("http://www.ersan.com.tr".replaceFirst("^https?:\\/\\/(www.)?", "")) | |
println("https://ersan.com.tr".replaceFirst("^https?:\\/\\/(www.)?", "")) | |
println("http://ersan.com.tr".replaceFirst("^https?:\\/\\/(www.)?", "")) | |
println("www.ersan.com.tr".replaceFirst("^(https?:\\/\\/)?(www.)?", "")) | |
println("ersan.com.tr".replaceFirst("^https?:\\/\\/(www.)?", ""))*/ | |
1 to 100 foreach { _ => | |
try { | |
con = new URL(url).openConnection().asInstanceOf[HttpURLConnection] | |
con.setInstanceFollowRedirects(false) | |
locHeader = con.getHeaderField("location") | |
println(locHeader) | |
domainName = locHeader.replaceFirst("^(https?://)?(www.)?", "") | |
println(domainName) | |
con = new URL(locHeader).openConnection().asInstanceOf[HttpURLConnection] | |
resCode= con.getResponseCode | |
urlStatusMap += (domainName -> resCode) | |
println(s"${domainName} , ${resCode}") | |
} catch { | |
case e => println(e.printStackTrace()) | |
urlStatusMap += (domainName -> -1) | |
} | |
} | |
urlStatusMap.foreach( x=>println(s" ${x._1} , ${if (x._2 != 200) x._2 }") ) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment