MATLAB: Finding all the packets associated with particular IP address

findingip addressnetworkinsortingunique

say we have a matrix of nx4 .
like
no. src_ip dest_ip port
1 172.20.1.1 65.34.29.92 443
2 162.37.82.93 172.20.1.1 80
3. 162.37.76.29 172.20.1.2 534
4. 65.43.29.88 172.20.112.12 764
we have to find all the packets with all the corresponding column values associated with an ip , say 65.34.xx.xx .
any solutions …please

Best Answer

Man, this is what AWK was built for! But never mind. To do it in MatLab, use regular expressions:
packethist = {
1 '72.20.1.1' '65.34.29.92' 443
2 '162.37.82.93' '172.20.1.1' 80
3 '162.37.76.29' '172.20.1.2' 534
4 '65.43.29.88' '172.20.112.12' 764 };
rows = find( ~cellfun(@isempty, regexp(packethist(:,2), '^65\.43\.')) );
Explanation:
I pass your second column to regexp and use the matching criteria '^65\.43\.' which looks for the text '65.43.' at the beginning of the string.
The regexp call returns a cell array containing a match list (the index where the matching text begins), or an empty cell (if no match).
I then pass that into cellfun which maps the isempty function over the regexp result array. That tells me which cells are empty, so I negate it (with ~) and run find to return the row indices.
You can then grab the filtered rows as follows:
packethist(rows, :)
Of course, you don't need the find call. That's just to get row numbers. The result of the cellfun call is a logical array, which you can also use as an index:
matches = ~cellfun(@isempty, regexp(packethist(:,2), '^65\.43\.'));
packethist(matches, :)
Hehe, I keep editing to expand this answer. One more thing... If you also want to include the destination IP, then compute the same kind of matches logical array as above for the destination column and combine them:
srcMatch = ...
destMatch = ...
matches = srcMatch | destMatch; % Either source or dest
matches = srcMatch & destMatch; % Both source and dest