Skip to content

Instantly share code, notes, and snippets.

@bigsnarfdude
Created May 13, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigsnarfdude/0c29a729d0dce6b0caae to your computer and use it in GitHub Desktop.
Save bigsnarfdude/0c29a729d0dce6b0caae to your computer and use it in GitHub Desktop.
Scala Algebird for IP Address count attack traffic
case class OutsideServer(val ipAddress: String, val LoginsPerMinute: Int) extends Ordered[OutsideServer] {
def compare(that: OutsideServer): Int = {
val count = this.LoginsPerMinute - that.LoginsPerMinute
if (count == 0) this.ipAddress.compareTo(that.ipAddress) else count
}
}
case class InsideServer(val ipAddress: String, val LoginsPerMinute: Int) extends Ordered[InsideServer] {
def compare(that: InsideServer): Int = {
val count = this.LoginsPerMinute - that.LoginsPerMinute
if (count == 0) this.ipAddress.compareTo(that.ipAddress) else count
}
}
val oneOneOneOne = OutsideServer("1.1.1.1", 40267391)
val twoTwoTwoTwo = OutsideServer("2.2.2.2", 48013573)
val threeThreeThreeThree = OutsideServer("3.3.3.3", 40756470)
val fourFourFourFour = OutsideServer("4.4.4.4", 25731)
val fiveFiveFiveFive = OutsideServer("5.5.5.5", 37125055)
val tenTenTenTen = InsideServer("10.10.10.10", 91)
val tenTwentyTwentyTwenty = InsideServer("10.20.20.20", 73)
val tenThirtyThirtyThirty = InsideServer("10.30.30.30", 70)
val tenFourtyFourtyFourty = InsideServer("10.40.40.40", 31)
val tenFiftyFiftyFifty = InsideServer("50.50.50.50", 55)
val heavyHitterOutside: Max[OutsideServer] = Max(oneOneOneOne) + Max(twoTwoTwoTwo) + Max(threeThreeThreeThree) + Max(fourFourFourFour) + Max(fiveFiveFiveFive)
val lowLoginsInside: Min[InsideServer]= Min(tenTenTenTen) + Min(tenTwentyTwentyTwenty) + Min(tenThirtyThirtyThirty) + Min(tenFourtyFourtyFourty) + Min(tenFiftyFiftyFifty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment