Hi Experts
I need to do investigation of web log data and need to see the IP address origination. For a referral match, I searched over internet and found a range of IPs(not the actual IP list) . Below the Sample of From IP to IP
From To Count
1.6.0.0 | 1.7.255.255 | 131072 |
1.22.0.0 | 1.23.255.255 | 131072 |
1.38.0.0 | 1.39.255.255 | 131072 |
1.186.0.0 | 1.186.255.255 | 65536 |
1.187.0.0 | 1.187.255.255 | 65536 |
In the first record, the list would be as I could understand
1.6.0.0 , 1.6.0.1 .........1.6.0.255, 1.6.1.0, 1.6.1.1 .....1.6.1.255 and so on. Every octect needs to be countered till the "TO" IP
How can this be achieved considering the volume of ranges exisiting
Any help or alternative would be appreciated
Thanks in Advance
Regards
Hi,
Well, I would suggest you need 4 nested do loops, something along the lines of:
data want;
do I=1 to 1;
do j=6,7,22,23,38,39,186,187; /* updated for all */
do k=0 to 255;
do l=0 to 255;
ip=compress(put(I,best.)||'.'||put(j,best.)||'.'||put(k,best.)||'.'||put(l,best.));
output;
end;
end;
end;
end;
run;
Hi,
Well, I would suggest you need 4 nested do loops, something along the lines of:
data want;
do I=1 to 1;
do j=6,7,22,23,38,39,186,187; /* updated for all */
do k=0 to 255;
do l=0 to 255;
ip=compress(put(I,best.)||'.'||put(j,best.)||'.'||put(k,best.)||'.'||put(l,best.));
output;
end;
end;
end;
end;
run;
Many Many Thanks
This solution worked for me. I just made the looping dynamic and the code worked like charm. Many Thanks
IPv4 addressing is based on 4 bytes. They are based on bit/byte processing. Testing via mask's is easy with BAND BXOR
What you could do is accessing your problem just like that. Convert the decimal reprentation as it was in the IP protocol 4 bytes (char). SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition (byte)
The testing of ranges will just become a bit-check non zero after some band-masking.
This is a more complete approach:
%let start=1.6.0.0;
%let end=1.7.255.255;
data ip_ad (keep=ip_address);
start_ad = 0;
do i = 1 to 4;
i1 = input(scan("&start",i,'.'),3.);
start_ad = start_ad + i1 * 256**(4-i);
end;
end_ad = 0;
do i = 1 to 4;
i1 = input(scan("&end",i,'.'),3.);
end_ad = end_ad + i1 * 256**(4-i);
end;
length ip_address $ 15;
do address = start_ad to end_ad;
ip_address = ' ';
char_ad = put(address,hex8.);
do i = 0 to 3;
ip_address = compress(ip_address !! put(input(substr(char_ad,i*2+1,2),hex2.),best3.));
if i ne 3 then ip_address = trim(ip_address) !! '.';
end;
output;
end;
run;
RW9's example would have problems with
start=1.7.0.0
end=2.6.255.255
Thanks guys. The logics have really helped me build my ip address repository
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.