The Julia network functions are in package Socket
and are formally documented at
Sockets
Julia has the abstract type IPAddr with subtypes
IPv4 and IPv6.
There are constructors for each, using an apprpopriate
integer for each e.g.
julia> IPv4(3223256218)
ip"192.30.252.154"
julia> IPv6(3223256218)
ip"::c01e:fc9a"
and also string constructors
julia> ip"127.0.0.1"
ip"127.0.0.1"
julia> @ip_str "2001:db8:0:0:0:0:2:1"
ip"2001:db8::2:1"
Julia uses the C function getaddrinfo() to get an IPv4 or IPv6 address
using a DNS lookup. A sample program is
IP.jl illustrates these:
using Sockets
if size(ARGS)[1] < 1
println("Usage: IP hostname")
exit(1)
end
try
global ip
ip = Sockets.getaddrinfo(ARGS[1], IPv6)
catch exc
println("No address")
exit(2)
end
println(ip)
To get all IP addresses for a host, use getalladdrinfo()
as in
IPs.jl illustrates these:
# See https://docs.julialang.org/en/v1/stdlib/Sockets/#Sockets.getaddrinfo
using Sockets
if size(ARGS)[1] < 1
println("Usage: IP hostname")
exit(1)
end
try
global ips
ips = Sockets.getalladdrinfo(ARGS[1])
catch exc
println("No address")
exit(2)
end
println(ips)
There doesn't seem to be anything yet.
Copyright © Jan Newmarch, jan@newmarch.name
" Network Programming using Java, Go, Python, Rust, JavaScript and Julia"
by
Jan Newmarch
is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License
.
Based on a work at
https://jan.newmarch.name/NetworkProgramming/
.