1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

tips on how to fake ip addresses

Discussion in 'Other Scripting Languages' started by mgaft1, Apr 19, 2009.

  1. mgaft1

    mgaft1 Newbie

    Joined:
    Oct 12, 2008
    Messages:
    22
    Likes Received:
    1
    I came across a task of importing my subscriber's list to the autoresponder
    service. Some of my subscriber's data didn't contain ip address, simply because at the time of collection, the thought of its necessity didn't cross my mind so I decided to populate the list with fake IP addresses. Of course, the task was to make these addresses as little "fake" as possible, meaning they had to be ip address from the Real US range.

    Since it took some time and effort to figure out how exactly accomplishes it, I thought it would be a good idea to post it, in case someone else might come across the same need. Now I am not claiming that the method I used is absolutely the best one out there, but I think it will be a good place to start.

    First I looked for a list of US ip ranges. I found one and I am attaching it with this post as a text file. Now if you look at several records from this file it structured as follow:
    60.254.128.0/18
    163.60.0.0/16
    192.103.43.0/24
    202.72.96.0/20
    202.76.240.0/21
    203.77.184.0/21
    203.144.48.0/20
    203.187.128.0/19
    Here the construct before the slash represents an ip address, while as the number after slash represents the variation of the last digit in IP address. In the example of the first records, this means that the entire range of possible IPs is the following:
    60.254.128.0/60.254.128.1/60.254.128.2/60.254.128.3/60.254.128.4/60.254.128.5/
    60.254.128.6/60.254.128.7 and so on until it reaches 60.254.128.18

    So I imported this text file into Sequel table that I called US_IP_ZONE with the following structure:

    CREATE TABLE [dbo].[Us_ip_zone](
    [ip_start] [varchar](20) NULL,
    [ip_end] [int] NULL,
    [done] [bit] NOT NULL CONSTRAINT [DF_Us_ip_zone_done] DEFAULT ((0))
    ) ON [PRIMARY]

    Here the field [ip_start] stored ip address while [ip_end] stored the variation digit. The third [done] had to do with subsequent scan and I will touch up on it later.

    Now, surly I didn't want to poulate my table with all the ips from the same record sequentually. This would siounds suspicious. Instead decided to take a random number from 0 to 18 (again I am taking the first record as an example) and construct the last digit of ip address based on this selection. For istance if the randome number would be 7 the resulting ip address will be 60.254.128.7, if it would be 12 then 60.254.128.12, if 15 then 60.254.128.15 etc.

    In terms of sequel statement this objective is achieved with the following query:
    select @ip_address = substring(ip_start,1,len(ip_start) - charIndex('.',reverse(ip_start))+1)+convert(varchar(3),round(rand()*ip_end,0)) ,@ip_start = ip_start
    from
    (
    select top 1 *
    from us_ip_zone where done = 0
    ) t

    Here the internal select separates a top record from the [US_IP_ZONE] table. The external select cuts out the existing address up to the last period and replaces the last digit with the number randomly selected from range. The @ip_start variable populated in order to update the update this record as "used" or "done" in this loop, so that next internal select will give me the next record. Here's how the entire script looks like...

    declare @ID int
    declare @ip_address varchar(15)
    declare @ip_start varchar(15)
    declare @found bit
    declare cr cursor for
    select id from emails_no_ip
    where recepient_IP is null

    open cr

    fetch next from cr into @ID

    while @@fetch_status = 0
    begin
    select @found = 0
    while @found = 0
    begin
    select @ip_address = substring(ip_start,1,len(ip_start) - charIndex('.',reverse(ip_start))+1)+convert(varchar(3),round(rand()*ip_end,0))
    ,@ip_start = ip_start
    from (
    select top 1 *
    from us_ip_zone where done = 0
    ) t

    if exists(select 1 from emails_exported where recepient_IP = @ip_Address)
    CONTINUE
    else
    begin
    if exists(select 1 from emails_no_ip where recepient_IP = @ip_Address)
    CONTINUE
    else
    begin
    update emails_no_ip set recepient_IP = @ip_Address where ID = @ID
    break
    select @found = 1
    end
    end
    end
    update us_ip_zone set done = 1 where ip_start = @ip_start

    fetch next from cr into @ID
    end

    close cr
    deallocate cr

    As you can see first I am generating the perspective ip, then I check whether this ip exists among real collected ips in the table [emails_exported]. Then I check whether the perspective ip exists in the table that I attempt to populate [emails_no_ip] to make sure that this ip hasn't been used before. Now in case either table already contains the ip I loop again and generate another perspective ip from the same source record, until the ip is indeed unique. Once uniqueness of perspective IP is ensured the scrip updates the [recepient_IP] field in the target table.

    The last statement of the loop updates the current record from [US_IP_ZONE] table so that next loop will have a different source IP record to deal with.

    That's all folks.:)
     

    Attached Files:

    Last edited: Apr 19, 2009
  2. KevinK

    KevinK Junior Member

    Joined:
    Jul 24, 2008
    Messages:
    159
    Likes Received:
    87

    :eek: WHO ON GOD'S GREEN EARTH TOLD YOU THAT!!! :eek:

    Go do a study on VLSM and CIDR and come back when you are ready to correct this post... I can't even continue reading this post until this is corrected!! Sorry, but that's where I stand.

    G: What is CIDR
     
  3. voyevoda

    voyevoda Regular Member Premium Member

    Joined:
    Mar 21, 2010
    Messages:
    217
    Likes Received:
    97
    Location:
    Eastern Front
    You can get a list of address ranges in CIDR notation from blockacountry.com.


    Host and network bits are hard; let's go shopping! :)
     
  4. tgthe1

    tgthe1 Newbie

    Joined:
    Sep 22, 2010
    Messages:
    16
    Likes Received:
    0
    Is there software that generates IP addresses for you?
     
  5. mymindrules27

    mymindrules27 Newbie

    Joined:
    Jul 10, 2010
    Messages:
    45
    Likes Received:
    2
    How can we use generated ip addresse?s
     
  6. deenmean

    deenmean Junior Member

    Joined:
    Feb 28, 2008
    Messages:
    121
    Likes Received:
    48
    OMgosh
    www.autohotkey.com , powerful, easy to learn, FREE.

    Code:
    loop, 1000 ; if you want 1000 of them
    {
    
    
    
    
    ;lets say the range is from one of these big boys http://www.networksolutions.com/whois/results.jsp?ip=24.1.1.1 http://www.networksolutions.com/whois/results.jsp?ip=64.1.1.1 http://www.networksolutions.com/whois/results.jsp?ip=12.1.1.1
    ;then do this
    Random, randomIP1, 2, 254
    Random, randomIP2, 2, 254
    Random, randomIP3, 2, 254
    
    IP1 = 12.%randomIP1%.%randomIP2%.%randomIP3%
    
    
    Random, randomIP1, 2, 254
    Random, randomIP2, 2, 254
    Random, randomIP3, 2, 254
    
    IP2 = 24.%randomIP1%.%randomIP2%.%randomIP3%
    
    
    Random, randomIP1, 2, 254
    Random, randomIP2, 2, 254
    Random, randomIP3, 2, 254
    
    IP3 = 64.%randomIP1%.%randomIP2%.%randomIP3%
    
    FileAppend,
    (
    %IP1%
    %IP2%
    %IP3%
    
    ), c:\ips.txt
    
    }
    
    
     
  7. hiderightnow

    hiderightnow Junior Member

    Joined:
    Jul 19, 2010
    Messages:
    104
    Likes Received:
    22
    I understand your need to populate the DB with US ip's, but man, are you getting tangled with it... You really don't need to know every subnet known to man from the US to make your DB happy :) and the population procedure seems kind of time consuming.