Skip to content

Instantly share code, notes, and snippets.

@concerned3rdparty
Last active August 29, 2015 14:22
Show Gist options
  • Save concerned3rdparty/b68114ec802cfc93a29b to your computer and use it in GitHub Desktop.
Save concerned3rdparty/b68114ec802cfc93a29b to your computer and use it in GitHub Desktop.
Random Url Response examination
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