Skip to content

Instantly share code, notes, and snippets.

@joshrendek
Last active December 27, 2015 03:29
Show Gist options
  • Save joshrendek/7259252 to your computer and use it in GitHub Desktop.
Save joshrendek/7259252 to your computer and use it in GitHub Desktop.
package com.joshrendek.scalabgp
import org.openqa.selenium.htmlunit._
import scala.collection.JavaConversions._
import org.openqa.selenium.By
case class ASMeta(as: String, name: String)
object AutonomousSystem {
def apply(as: Integer, port: Option[Int]): AutonomousSystem = {
new AutonomousSystem(as, fetchPeerList(as, port))
}
def fetchPeerList(as: Integer, port: Option[Int]): List[ASMeta] = {
val url = "http://bgp.he.net/AS" + as
val driver = new HtmlUnitDriver
if (port.isDefined) {
driver.setProxy("localhost", port.get)
}
driver.get(url)
val peers = driver.findElementsByXPath("//*[@id=\"table_peers4\"]/tbody/tr")
peers.map {
peer =>
val row = peer.findElements(By.tagName("td")).map(f => f.getText).toList
new ASMeta(row(0), row(1))
}.toList
}
}
class AutonomousSystem(val as: Integer, val peerList: List[ASMeta]) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment