Skip to content

Instantly share code, notes, and snippets.

@AndriusA
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save AndriusA/5a4bace2cd2a532296eb to your computer and use it in GitHub Desktop.

Select an option

Save AndriusA/5a4bace2cd2a532296eb to your computer and use it in GitHub Desktop.
library(ggplot2)
library(splines)
library(MASS)
library(plyr)
library(reshape)
library(scales)
options(scipen=999)
traffic<-read.table("trafficEvents.txt", header=TRUE, sep="," ,as.is=FALSE)
traffic<-transform(traffic, TIME = as.numeric(TIME))
traffic<-transform(traffic, SRCPORT = as.numeric(SRCPORT))
traffic<-transform(traffic, DSTPORT = as.numeric(DSTPORT))
#Apps under study
# trafficApps<-subset(traffic, (traffic$PACKAGE=="com.google.android.gms" | traffic$PACKAGE=="com.whatsapp" | traffic$PACKAGE=="com.facebook.katana" | traffic$PACKAGE=="com.skype.raider" | traffic$PACKAGE=="com.viber.voip") & traffic$SCREEN == 0)
createConnID <- function(line) {
if (line['DIRECTION'] == -1) {
return (paste0(line['SRC'], "-", line['DST'], "-", line['SRCPORT'], "-", line['DSTPORT']))
} else {
return (paste0(line['DST'], "-", line['SRC'], "-", line['DSTPORT'], "-", line['SRCPORT']))
}
}
connectionDuration <- function(x) {
a = x['maxTime']-x['minTime']
colnames( a) = 'duration'
a
}
# We look only at cmod as we can accurately attribute PID to packet, and only at TCP
trafficApps<-subset(traffic, traffic$OSVERSION==10 & traffic$USER!="rip" & traffic$PROTOCOL=="TCP")
# users<-levels(factor(trafficApps$USER))
# apps <- levels(factor(trafficApps$PACKAGE))
trafficApps <- subset(trafficApps, trafficApps$PACKAGE=="com.facebook.katana")
# Calculate the duration of each connection
trafficApps$ConnectionID = apply(trafficApps, 1, createConnID)
timestamped <- ddply(trafficApps, .(ConnectionID,PACKAGE), transform, minTime = min(TIME), maxTime = max(TIME))
trafficApps = cbind(trafficApps,connectionDuration(timestamped))
head(count(trafficApps, c('ConnectionID', 'PACKAGE', 'duration')))
> head(count(trafficApps, c('ConnectionID', 'PACKAGE', 'duration')))
ConnectionID PACKAGE duration freq
1 10.135.206.76-173.194.35.135-47946- 80 com.facebook.katana 5975 30
2 10.135.206.76-173.194.35.135-47946- 80 com.facebook.katana 50990 9
3 10.135.206.76-173.194.35.135-47946- 80 com.facebook.katana 90964 2
4 10.135.206.76-173.194.35.135-47946- 80 com.facebook.katana 96060 1
5 10.135.206.76-173.194.69.138-54462- 80 com.facebook.katana 36048 1
6 10.135.206.76-173.194.69.138-54462- 80 com.facebook.katana 39987 27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment