Tracking Instances of a String
in
Programming Questions
•
2 years ago
Hi everyone.
I'm working on a sketch to build a set of 3D objects based off information gathered from tcpdump. I've setup a class called 'packet' that contains the source, destination, and protocol of each packet I've captured. All of the packet objects are stored in an array.
I would like to have the sketch walk through this array and group packet objects that have matching source strings together with hopes of drawing cubes for each source in a similar x, y, z space.
My code is a mess, I'm a bit frustrated, and I feel like I need a fresh perspective on the problem.
Here's the code with different attempts commented out:
CSV File "csv":
- "1","0.000000","10.73.30.223","255.255.255.255","DB-LSP-DISC","Dropbox LAN sync Discovery Protocol"
- "2","0.000354","10.73.30.223","10.73.31.255","DB-LSP-DISC","Dropbox LAN sync Discovery Protocol"
- "3","0.072580","184.50.45.206","10.73.27.148","TCP","[TCP segment of a reassembled PDU]"
- "4","0.072807","184.50.45.206","10.73.27.148","TCP","[TCP segment of a reassembled PDU]"
- "5","0.073097","184.50.45.206","10.73.27.148","TCP","[TCP segment of a reassembled PDU]"
- boolean firstRun = true;
- boolean debug = true;
- String[] csvStrings;
- ArrayList packetZones;
- ArrayList knownSource;
- ArrayList knownDest;
- Packet[] packetArray;
- int mC = 0; //Master Counter
- void setup() {
- size(1280,720, P3D);
- scene = new Scene(this);
- csvStrings = loadStrings("csv");
- packetArray = new Packet[csvStrings.length];
- knownSource = new ArrayList();
- packetZones = new ArrayList();
- knownSource.add("127.0.0.1"); //Go ahead and add localhost as filler
- if(debug) println("Setting up packet objects");
- for(int i=0; i < csvStrings.length; i++) {
- String[] pieces = split(csvStrings[i], ',');
- packetArray[i] = new Packet(pieces);
- }
- }
- void draw() {
- for(int i=0; i < packetArray.length; i++){
- String currSource = packetArray[i].source;
- for(int j=i; j < packetArray.length; j++){
- if(currSource.equals(packetArray[j].source){
- //STOPPED HERE OUT OF FRUSTRATION/SLEEP DEPRIVATION
- //AND THE HEAVENS DID RUMBLE WITH OUR LORD'S KEEN DISPLEASURE
- }
- // while(mC < csvStrings.length) {
- // String[] pieces = split(csvStrings[mC], ',');
- // packetArray[mC] = new Packet(pieces);
- // if(firstRun) {
- // knownSource.add(packetArray[mC].source);
- // packetArray[mC].zoned = true;
- // firstRun = false;
- // if(debug) println("First run completed.");
- // }
- // for(int i=0; i < packetArray.length; i++) {
- // for(int j=0; j < knownSource.size(); j++) {
- // String currSource = (String) knownSource.get(j);
- // if(!packetArray[i].source.equals(currSource) && packetArray[i].zoned != true) {
- // knownSource.add(packetArray[mC].source);
- // packetArray[i].zoned = true;
- // if(debug) {
- // println("Added unknown source: " + packetArray[mC].source);
- // println("# known sources: " + knownSource.size());
- // println(packetArray[mC].zoned);
- // }
- // }
- // }
- // }
- // mC++;
- // }
- // if(debug) println("while() loop finished inside of draw()");
- // String[] pieces = split(csvStrings[mC], ',');
- // packetArray[mC] = new Packet(pieces);
- // for(int i=0; i < knownSource.size(); i++) {
- // if(packetArray[mC].source.equals(knownSource.get(i))) {
- // packetArray[mC].singular = false;
- // knownSource.add(packetArray[mC].source);
- // }else if(!packetArray[mC].source.equals(knownSource.get(i))){
- // packetArray[mC].singular = true;
- // }
- // println(packetArray[mC].singular);
- // println(knownSource.size());
- // println(knownSource);
- // mC++;
- // }
- //void drawBoxes() {
- // int counter = 0;
- // for(int i=0; i < recordCount; i++) {
- // for(int j=0; j < recordCount; j++) {
- // if(dumpRecords[i].source.equals("\"10.73.27.148\"")) {
- //
- // }
- // }
- // if(counter > 0) {
- // println(dumpRecords[i].source + " matches: " + counter);
- // counter = 0;
- // }
- // }
- // firstRun = false;
- //}
- // for(int i=0; i < csvStrings.length; i++) {
- // String[] pieces = split(csvStrings[i], ',');
- // dumpRecords[recordCount] = new Record(pieces);
- // recordCount++;
- // }
- class Packet {
- boolean singular;
- boolean zoned = false;
- String number;
- String time;
- String source;
- String dest;
- String protocol;
- String info;
- int xPos;
- int yPos;
- int zPos;
- public Packet(String[] dumpLine){
- number = dumpLine[0];
- time = dumpLine[1];
- source = dumpLine[2];
- dest = dumpLine[3];
- protocol = dumpLine[4];
- info = dumpLine[5];
- }
- public void setPosition(int x, int y, int z){
- xPos = x;
- yPos = y;
- zPos = z;
- }
- }
- class PacketZone {
- boolean sourceZone = false;
- boolean destZone = false;
- boolean undefined = true;
- String name;
- String source;
- String dest;
- int xMin;
- int yMin;
- int zMin;
- int xArea;
- int yArea;
- int zArea;
- public PacketZone(String passedName, int minx, int x, int miny, int y, int minz, int z){
- name = passedName;
- xMin = minx;
- yMin = miny;
- zMin = minz;
- xArea = x;
- yArea = y;
- zArea = z;
- }
- public void setSource(String thisSource){
- source = thisSource;
- sourceZone = true;
- undefined = false;
- if(destZone){
- println("WHOA whoa whoa. I was a destZone!");
- }
- }
- public void setDest(String destination){
- dest = destination;
- destZone = true;
- undefined = false;
- if(sourceZone){
- println("WHOA whoa whoa. I was a sourceZone!");
- }
- }
- }
1