Last active
December 27, 2015 03:29
-
-
Save joshrendek/7259252 to your computer and use it in GitHub Desktop.
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 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