This commit is contained in:
benfry
2011-01-26 19:22:19 +00:00
parent d3a18c7964
commit eb64b2d4fc
1234 changed files with 96518 additions and 0 deletions
@@ -0,0 +1,85 @@
/**
* Carnivore Client
* by Alexander R. Galloway.
* The Carnivore library for Processing allows the programmer to run a packet
* sniffer from within the Processing environment. A packet sniffer is any
* application that is able to indiscriminately eavesdrop on data traffic
* traveling through a local area network (LAN).
*
* Note: requires Carnivore Library for Processing v2.2 (http://r-s-g.org/carnivore)
* Windows, first install winpcap (http://winpcap.org)
* Mac, first open a Terminal and execute this commmand: sudo chmod 777 /dev/bpf*
* (must be done each time you reboot your mac)
*/
import java.util.Iterator;
import org.rsg.carnivore.*;
import org.rsg.carnivore.net.*;
HashMap nodes = new HashMap();
float startDiameter = 100.0;
float shrinkSpeed = 0.97;
int splitter, x, y;
PFont font;
void setup()
{
size(800, 600);
background(255);
frameRate(10);
Log.setDebug(true); // Uncomment this for verbose mode
CarnivoreP5 c = new CarnivoreP5(this);
//c.setVolumeLimit(4);
// Use the "Create Font" tool to add a 12 point font to your sketch,
// then use its name as the parameter to loadFont().
font = loadFont("CourierNew-12.vlw");
textFont(font);
}
void draw()
{
background(255);
drawNodes();
}
// Iterate through each node
synchronized void drawNodes() {
Iterator it = nodes.keySet().iterator();
while (it.hasNext()) {
String ip = (String)it.next();
float d = float(nodes.get(ip).toString());
// Use last two IP address bytes for x/y coords
splitter = ip.lastIndexOf(".");
y = int(ip.substring(splitter + 1)) * height / 255; // Scale to applet size
String tmp = ip.substring(0, splitter);
splitter = tmp.lastIndexOf(".");
x = int(tmp.substring(splitter + 1)) * width / 255; // Scale to applet size
// Draw the node
stroke(0);
fill(color(100, 200)); // Rim
ellipse(x, y, d, d); // Node circle
noStroke();
fill(color(100, 50)); // Halo
ellipse(x, y, d + 20, d + 20);
// Draw the text
fill(0);
text(ip, x, y);
// Shrink the nodes a little
nodes.put(ip, str(d * shrinkSpeed));
}
}
// Called each time a new packet arrives
synchronized void packetEvent(CarnivorePacket packet)
{
println("[PDE] packetEvent: " + packet);
// Remember these nodes in our hash map
nodes.put(packet.receiverAddress.toString(), str(startDiameter));
nodes.put(packet.senderAddress.toString(), str(startDiameter));
}
@@ -0,0 +1,52 @@
/**
* Chat Server
* by Tom Igoe.
*
* Press the mouse to stop the server.
*/
import processing.net.*;
int port = 10002;
boolean myServerRunning = true;
int bgColor = 0;
int direction = 1;
int textLine = 60;
Server myServer;
void setup()
{
size(400, 400);
textFont(createFont("SanSerif", 16));
myServer = new Server(this, port); // Starts a myServer on port 10002
background(0);
}
void mousePressed()
{
// If the mouse clicked the myServer stops
myServer.stop();
myServerRunning = false;
}
void draw()
{
if (myServerRunning == true)
{
text("server", 15, 45);
Client thisClient = myServer.available();
if (thisClient != null) {
if (thisClient.available() > 0) {
text("mesage from: " + thisClient.ip() + " : " + thisClient.readString(), 15, textLine);
textLine = textLine + 35;
}
}
}
else
{
text("server", 15, 45);
text("stopped", 15, 65);
}
}
@@ -0,0 +1,29 @@
/**
* HTTP Client.
*
* Starts a network client that connects to a server on port 80,
* sends an HTTP 1.1 GET request, and prints the results.
*/
import processing.net.*;
Client c;
String data;
void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "www.processing.org", 80); // Connect to server on port 80
c.write("GET / HTTP/1.1\n"); // Use the HTTP "GET" command to ask for a Web page
c.write("Host: my_domain_name.com\n\n"); // Be polite and say who we are
}
void draw() {
if (c.available() > 0) { // If there's incoming data from the client...
data = c.readString(); // ...then grab it and print it
println(data);
}
}
@@ -0,0 +1,46 @@
/**
* Shared Drawing Canvas (Client)
* by Alexander R. Galloway.
*
* The Processing Client class is instantiated by specifying a remote
* address and port number to which the socket connection should be made.
* Once the connection is made, the client may read (or write) data to the server.
* Before running this program, start the Shared Drawing Canvas (Server) program.
*/
import processing.net.*;
Client c;
String input;
int data[];
void setup()
{
size(450, 255);
background(204);
stroke(0);
frameRate(5); // Slow it down a little
// Connect to the server's IP address and port
c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port
}
void draw()
{
if (mousePressed == true) {
// Draw our line
stroke(255);
line(pmouseX, pmouseY, mouseX, mouseY);
// Send mouse coords to other person
c.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
}
// Receive data from server
if (c.available() > 0) {
input = c.readString();
input = input.substring(0, input.indexOf("\n")); // Only up to the newline
data = int(split(input, ' ')); // Split values into an array
// Draw line using received coords
stroke(0);
line(data[0], data[1], data[2], data[3]);
}
}
@@ -0,0 +1,50 @@
/**
* Shared Drawing Canvas (Server)
* by Alexander R. Galloway.
*
* A server that shares a drawing canvas between two computers.
* In order to open a socket connection, a server must select a
* port on which to listen for incoming clients and through which
* to communicate. Once the socket is established, a client may
* connect to the server and send or receive commands and data.
* Get this program running and then start the Shared Drawing
* Canvas (Client) program so see how they interact.
*/
import processing.net.*;
Server s;
Client c;
String input;
int data[];
void setup()
{
size(450, 255);
background(204);
stroke(0);
frameRate(5); // Slow it down a little
s = new Server(this, 12345); // Start a simple server on a port
}
void draw()
{
if (mousePressed == true) {
// Draw our line
stroke(255);
line(pmouseX, pmouseY, mouseX, mouseY);
// Send mouse coords to other person
s.write(pmouseX + " " + pmouseY + " " + mouseX + " " + mouseY + "\n");
}
// Receive data from client
c = s.available();
if (c != null) {
input = c.readString();
input = input.substring(0, input.indexOf("\n")); // Only up to the newline
data = int(split(input, ' ')); // Split values into an array
// Draw line using received coords
stroke(0);
line(data[0], data[1], data[2], data[3]);
}
}
@@ -0,0 +1,50 @@
/**
* Yahoo! Search.
*
* Download the Yahoo! Search SDK from http://developer.yahoo.com/download
* Inside the download, find the yahoo_search-2.X.X.jar file somewhere inside
* the "Java" subdirectory. Drag the jar file to your sketch and it will be
* added to your 'code' folder for use.
*
* This example is based on the based on Yahoo! API example.
*/
// Replace this with a developer key from http://developer.yahoo.com
String appid = "YOUR_DEVELOPER_KEY_HERE";
SearchClient client = new SearchClient(appid);
String query = "processing.org";
WebSearchRequest request = new WebSearchRequest(query);
// (Optional) Set the maximum number of results to download
//request.setResults(30);
try {
WebSearchResults results = client.webSearch(request);
// Print out how many hits were found
println("Displaying " + results.getTotalResultsReturned() +
" out of " + results.getTotalResultsAvailable() + " hits.");
println();
// Get a list of the search results
WebSearchResult[] resultList = results.listResults();
// Loop through the results and print them to the console
for (int i = 0; i < resultList.length; i++) {
// Print out the document title and URL.
println((i + 1) + ".");
println(resultList[i].getTitle());
println(resultList[i].getUrl());
println();
}
// Error handling below, see the documentation of the Yahoo! API for details
}
catch (IOException e) {
println("Error calling Yahoo! Search Service: " + e.toString());
e.printStackTrace();
}
catch (SearchException e) {
println("Error calling Yahoo! Search Service: " + e.toString());
e.printStackTrace();
}