Making wild guesses that the requestor wants any possible combination of field 2 and field 5 in a large comma separated file of numbers, I get at
$ awk 'BEGIN {SUBSEP=":"}
NR==1 {next}
{IP1[$2]++;PORT2[$2,$5]++}
END {for (i in PORT2) {x=index(i,SUBSEP); j=substr(i,1,x-1); print "IP1=" j ": " IP1[j] ", PORT2=" substr(i,x+1)": "PORT2}}
' FS="," file
IP1=1: 1, PORT2=5: 1
IP1=2: 2, PORT2=5: 1
IP1=2: 2, PORT2=6: 1
IP1=3: 3, PORT2=5: 2
IP1=3: 3, PORT2=6: 1
Input file would be sth like
datetime,ip1,port1,ip2,port2,number
9,1,8,7,5,4
9,2,8,7,5,4
9,3,8,7,5,4
9,3,8,7,5,4
9,2,8,7,6,4
9,3,8,7,6,4