filtering out matching IP addresses in form of 172.20.xxx.xxx from a cell S

a and b is given in the problem in the form of cell as shown below. actually a and b are two columns of a nx2 cell
>> a = s(:,1);
a =
'172.20.113.214'
'172.20.113.214'
'46.45.178.252'
'46.45.178.252'
'172.20.113.214'
'172.20.113.214'
'172.20.113.214'
'95.211.85.42'
'172.20.113.214'
'172.20.113.214'
'172.20.113.214'
'172.20.113.214'
'172.20.113.214'
'46.45.178.252'
'46.45.178.252'
'46.45.178.252'
>> b = s(:,2);
b =
'172.20.113.214'
'79.141.216.70'
'79.141.216.70'
'172.20.113.214'
'172.20.113.214'
'172.20.113.214'
'115.112.2.20'
'172.20.113.214'
'115.112.2.20'
'115.112.2.20'
'172.20.113.214'
'172.20.113.214'
'115.112.2.20'
'115.112.2.20'
'172.20.113.214'
'172.20.113.214'
'115.112.2.20'
'115.112.2.20'
'115.112.2.20'
'115.112.2.20'
'172.20.113.214'
'115.112.2.20'
'94.23.30.97'
'115.112.2.20'
'115.112.2.20'
the problem statement is that we have to filter out a certain list of resolved host names from the n x 2 cell S.
say we have to remove all the traffic which does belong to this list of hosts C. C is given something like
>> c
c =
'172.20.xxx.xxx' - filtering for the whole subnet
'79.141.216.xx'
'95.211.85.42'
we have to remove the whole row from S in which any of the strings given in c occurs.
say if '172.20.113.214' occurs in a(1) then remove the first packet of a , if '79.141.216.70' appears in b(2) and b(3) then we should get the output with no string equal to any of the strings given in c.
each of the string of cell c has to be removed in the initial cell S , whether it is in (:,1) or (:,2) .

3 Comments

What have you done so far? What questions do you have?
In past questions you have already been shown how to regexp() and how to strcmp(). Are you still stuck on the question of how to determine the pattern to match against according to whether there are wildcard characters in the target ?
sir , the problem is i am unable to input the IP address automatically , i.e say we have a list of IP addresses in which many ip addresses are in the form of 192.168.xx.xx . such kind of patterns can be many more like many 172.20.xx.xx , 10.0.xx.xx , and so on will be there. so i want to input the feed from a different cell of the list of host i want to filter out , say ['172.20.xx.xx 192.168.xx.xx 10.0.xx.xx']. is there any way to input the data from a cell or an array. i am sorry for asking the question in a wrng way , i am now comfortable with regexp :) , but the input part is a bit tricky for me
sir Jan simon , suggested me a way out but thats going way too awkward for me

Sign in to comment.

 Accepted Answer

p = '(^172\.20\.\d{3}.\d{3})|(^79\.141\.216\.\d{2})|(^95\.211\.85\.42)'
aout = a(cellfun('isempty',regexp(a,p)))
bout = b(cellfun('isempty',regexp(b,p)))
EDITED after Karan's comment here
c ={'172.20.xxx.xxx'
'79.141.216.xx'
'95.211.85.42'}
p = regexprep(cell2mat(strcat('(^',c.',')|')),{'\.' 'x' '\|$'},{'\\.' '\\d' ''});
aout = a(cellfun('isempty',regexp(a,p)))
bout = b(cellfun('isempty',regexp(b,p)))
ADDED after Karan's comment in question
c = '172.20.xx.xx 192.168.xx.xx 10.0.xx.xx'
p = ['(^',regexprep(c,{'\.','xx',' '},{'\\.' '\\d{2]',')|(^'}),')'];

2 Comments

cant we feed p as an input from a csv file or so. or we have to type the total list the way its written above ??

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!