BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bnarang
Calcite | Level 5

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.01.7.255.255131072
1.22.0.01.23.255.255131072
1.38.0.01.39.255.255131072
1.186.0.01.186.255.25565536
1.187.0.01.187.255.25565536


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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

bnarang
Calcite | Level 5

Many Many Thanks

This solution worked for me. I just made the looping dynamic and the code worked like charm. Many Thanks

jakarman
Barite | Level 11

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.

---->-- ja karman --<-----
Kurt_Bremser
Super User

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

bnarang
Calcite | Level 5

Thanks guys. The logics have really helped me build my ip address repository

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1213 views
  • 6 likes
  • 4 in conversation