Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created April 19, 2009 16:58
Show Gist options
  • Save jashkenas/98128 to your computer and use it in GitHub Desktop.
Save jashkenas/98128 to your computer and use it in GitHub Desktop.
# Note: If you've been using VMWare recently, it leaves some network
# services dangling. Kill the before you start the sketch:
# sudo killall vmnet-netifup
load_library 'carnivore'
require 'packet_listener'
include Java::PacketListener
def setup
@nodes = {}
@start_diameter = 150.0
@min_diameter = 30.0
@shrink_speed = 0.99
smooth
size 800, 600
ellipse_mode CENTER
@carnivore = org.rsg.carnivore.CarnivoreP5.new(self)
end
def draw
background 255
@nodes.each do |ip, d|
# Use last two IP address bytes for x/y coords
x = ip.split('.')[2].to_i * width / 255.0
y = ip.split('.')[3].to_i * height / 255.0
stroke 0
fill 100, 100, 100, 200
ellipse x, y, d, d
no_stroke
fill 100, 100, 100, 50
ellipse x, y, d + 20, d + 20
@nodes[ip] = (d * @shrink_speed) if d > @min_diameter
end
end
def packetEvent(p)
@nodes[p.receiverAddress.ip.to_s] = @start_diameter
@nodes[p.senderAddress.ip.to_s] = @start_diameter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment