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() endcatch err println("Simple Error:\n", err, "\n") println("Detailed Error: ", error(), "\n") println("Bactrace: ", backtrace()) exit()end
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)endglobal ipaddr = join(ip, ".")end
println("Bactrace: ", backtrace())
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.
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)endglobal 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)?