RandIP A random IP generator for Large scale network mapping.

295 views
Skip to first unread message

Jacob Yates

unread,
Aug 30, 2016, 1:26:29 AM8/30/16
to julia-users
I've been working on porting a script I wrote in python to julia and have been having some issues with the script freezing.

So pretty much all this script does is generate a random IP address and checks to see if its valid(the Python version will give http error codes) then logs the results for further analysis.

function gen_ip()
        ip = Any[]
        for i in rand(1:255, 4)
                push!(ip, i)
        end
        global ipaddr = join(ip, ".")
end

function test_ip()
        gen_ip()
        println("Testing IP: ", ipaddr)
        global socket = connect(ipaddr, 80)
end

function timer()
        sleep(5)
        close(socket)
end

try
        while true
                @async test_ip()
                @async timer()
                timer()
        end
catch err
        println("Simple Error:\n", err, "\n")
        println("Detailed Error: ", error(), "\n")
        println("Bactrace: ", backtrace())
        exit()
end


Páll Haraldsson

unread,
Aug 30, 2016, 11:34:49 AM8/30/16
to julia-users
On Tuesday, August 30, 2016 at 5:26:29 AM UTC, Jacob Yates wrote:
I've been working on porting a script I wrote in python to julia and have been having some issues with the script freezing.

So pretty much all this script does is generate a random IP address and checks to see if its valid(the Python version will give http error codes) then logs the results for further analysis.

function gen_ip()
        ip = Any[]
        for i in rand(1:255, 4)
                push!(ip, i)
        end
        global ipaddr = join(ip, ".")
end
 
[..]

        println("Bactrace: ", backtrace())

Note, there is a type for IP addresses, done like: ip"127.0.0.1" (should also work for IPv6) or:

gen_ip() = IPv4(rand(0:256^4-1)) #not sure why you excluded 0 in 1:255 (might want to exclude some IPs but not as much as you did?), or used global.

http://docs.julialang.org/en/release-0.4/manual/networking-and-streams/

Generally global is bad form, and I'm not sure, but it might have something to do with @async not working, as I guess it's not "thread-safe" or related..

--
Palli.

 
 

Páll Haraldsson

unread,
Sep 8, 2016, 9:15:22 AM9/8/16
to julia-users
On Tuesday, August 30, 2016 at 3:34:49 PM UTC, Páll Haraldsson wrote:
On Tuesday, August 30, 2016 at 5:26:29 AM UTC, Jacob Yates wrote:
I've been working on porting a script I wrote in python to julia and have been having some issues with the script freezing.

So pretty much all this script does is generate a random IP address and checks to see if its valid(the Python version will give http error codes) then logs the results for further analysis.

function gen_ip()
        ip = Any[]
        for i in rand(1:255, 4)
                push!(ip, i)
        end
        global ipaddr = join(ip, ".")
end
 
[..]

        println("Bactrace: ", backtrace())

Note, there is a type for IP addresses, done like: ip"127.0.0.1" (should also work for IPv6) or:

gen_ip() = IPv4(rand(0:256^4-1)) #not sure why you excluded 0 in 1:255 (might want to exclude some IPs but not as much as you did?), or used global.

gen_ip() = IPv4(begin r=rand(1:254); r >= 10 ? r+1 : r end, rand(0:255), rand(0:255), rand(0:255))

is possibly what you want. 0.x.x.x and 10.x.x.x are private networks and you seemed to want to exclude the former, and if also the latter then the new version does that. I forget, you where excluding 0 for the x-es, isn't that just plain wrong (except maybe for the last one)?


Páll Haraldsson

unread,
Sep 8, 2016, 9:17:53 AM9/8/16
to julia-users
FYI: There's also:

https://github.com/JuliaWeb/IPNets.jl

[And a thread on it, if I recall just an announcement.]

Didn't look into it much
Reply all
Reply to author
Forward
0 new messages