If I understand nsenter correctly, it just spawns a new shell inside the network namespace, but you probably still need root priviliges or the CAP_NET_RAW capability to access raw sockets (but I never worked with these namespaces).
Not really, you can run ICMP socket as a regular user if your user ID is within sysctl net.ipv4.ping_group_range. However that will require you to use datagram socket instead of raw socket:
And about the question of “how to get list of interfaces in the system”. Instead of playing with socket directly (especially as you are doing network namespacing, so obviously your view on interfaces will be limited) you should use:
But in this case you should not use ICMP protocol, but “just raw socket”, aka:
{:ok, socket} = :socket.open(:inet, :raw)
So this is pretty much different from your original question where you ask for the fetching list of the interfaces from raw ICMP socket.
:socket.ioctl(socket, :gifconf)
Will will return you only the configuration for the interface the socket is listening right now, not all that are available in the system.
Also I see the problem with your code - you define address map like %{:family => :inet, :port => 0} which is incorrect (weird that socket do not scream about it, or maybe it does, but you do not check the value returned by :socket.bind/2). It should be %{:family => :inet, :port => 0, :addr => address} as :addr field is mandatory according to the specs.