How to use python3 to connect to a ipv6 host using socket library - python-3.x

The following is my code in an attempt to connect to an IPv6 address host using sockets in python. However, all my attempts have resulted in the output "Network is unreachable". Could you point out what I am doing wrong and how it could be corrected?
import socket
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.connect(('2001:240:2408:8897:b4ac:9e51:ecc9:a388',8333,0,0))
OSError: [WinError 10051] A socket operation was attempted to an unreachable net
work

The only thing you did wrong is to give an IP address and port which is not reachable. It is also not reachable by other tools like telnet or netcat. The syntax itself is the correct one to connect to an IPv6 server. It will successfully connect if your for example replace the IP address with one for google.com and the port with 80 (http):
sock.connect(('2a00:1450:4001:81c::200e',80,0,0))

Related

MongoServerSelectionError: connect ECONNREFUSED ::1:27017

Before updating nodejs my code was working fine but after updating my nodejs version.
whenever i am connecting to the server(localhost), after connecting in a few seconds it gives me this error.
enter image description here
and in vs code console it gives
enter image description here
and this is my code:
enter image description here
I am trying to connect to my local database using the localhost server.
The error message indicates the application is attempting to connect to the IPv6 address ::1, i.e. localhost.
The code you have shows uses IPv4 localhost address 127.0.0.1, and appears to connect successfully at that point.
Some time later, another connection is attempted that goes to the IPv6 address.
This suggests that both:
something later uses localhost instead of an IP, and the operating system resolves that to ::1
mongod is not listening on the IPv6 address
To fix this, you could do one or more of:
modify the mongod.conf so that it listens on ::1 in addition to 127.0.0.1
search the code to find where localhost is used and change it to the IP4 address
modify the local operating system so localhost only resolves to an IP4 address (this is probably a bad idea)

Failed to complete tunnel connection error with ngrok

Failed to complete tunnel connection
The connection to http://cc1e064782fc.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:80.
Make sure that a web service is running on localhost:80 and that it is a valid address.
The error encountered was: dial tcp [::1]:80: connectex: No connection could be made because the target machine actively refused it.
Hi, I was setting up ngrok and got this error, I disabled the firewall too.
Take a look at this video where I show you the error.
https://youtu.be/uP4B79w4s7c
Its kind of a message that ngrok successfully created tunnel to your pc at port 80 but there is no service running at that port in your OS, Mostly people run a web server at 80 but you can run any service at that port.
So lets assume you are running a web server in your OS on port 80 then you can access that web server from anywhere on the internet using that ngrok tunnel.

Not able to access by IPv6 address by curl to Jboss server 8080 port

In dual stack mode my server is accessible in both IPv4 and IPv6 address from same machine.
If I execute curl command to that server from another machine, only IPv4 is working IPv6 is not working it shows below error:
curl: (7) Failed to connect to {IPv6 address} port 8080: Permission denied
This solves my problem
service ip6tables stop

Linux port blocked - This site can't be reached, refused to connect

I set my linux as an access point, and then run simple web-server that print "hello world" at port 3000.
and connect it with my smart phone successfully.
in linux terminal, http://localhost:3000 works well.
But in smart phone,
If I access to http://172.24.1.105:3000, can't connect to it. (172.24... is ap's ip)
the chrome's error message is
This site can't be reached. 172.24.1.105 refused to connect
I searched Google (https://serverfault.com/questions/725262/what-causes-the-connection-refused-message) and I suspicious linux's firewall.
pi#raspberrypi:~/prj/ap_server $ sudo tcpdump -n icmp
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
... when I access to port 3000,
15:07:13.102750 IP 192.168.0.3 > 168.126.63.2: ICMP 192.168.0.3 udp port 42531 unreachable, length 386
the log is above. so I couldn't reach ap's webserver.
so I wonder two things...
1. How can I disable to its port block?
2. in tcpdump log, I access to port 3000 actually, why the log print port 42531?
Plus)
even I type sudo service iptables stop, the problem is not solved
sudo netstat -ntlp | grep 3000 logs:
**tcp6 0 0 :::3000 :::* LISTEN 1999/nodejs**
+I followed this tutorial-> https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/ .
and there is ipv4 setting.
If you want to run it on your mobile it will work on Live IP (externel) address
if it is working fine on local address (localhost) and not on live IP then
enable routing from your router
and allow that specific port it will work fine.
I found the issue.
my dhcp set was
interface=wlan0 # Use interface wlan0
listen-address=172.24.1.1 # Explicitly specify the address to listen on
bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8 # Forward DNS requests to Google DNS
domain-needed # Don't forward short names
bogus-priv # Never forward addresses in the non-routed address spaces.
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
like above.
I tried to connect the external ip(172.24.1.105) that I can see on mobile continuously but got failed. but when I tried with 172.24.1.1, then success.
I don't know why. maybe there is accurate ip address and something in mobile is temporal.
See similar topic at Node JS not listening to port 1337 on server
Your web server is not listening remote address.

For locally running scala spray server, curl localhost works, but curl <local ip> gets "Connection refused"

Not sure what this issue has to do with spray specifically, but I tried to reproduce with a netty-based server, and curling the local ip seems to work fine. Does anyone know what might cause the following not to work even though it does work with a basic netty server:
$ ifconfig
eth0 Link encap:Ethernet HWaddr <my mac address>
inet addr:172.16.16.31
...
...
...
$ curl localhost:8080/myPath
myContent
$ curl 172.16.16.31:8080/myPath
curl: (7) Failed to connect to 172.16.16.31 port 8080: Connection refused
Advice on how to troubleshoot this issue is also welcome.
Found the issue. Answering here in case anyone else has the same problem. My spray server was initialized with a command like the following:
startServer(interface = "localhost", port = 8080) {
This specification of an interface appears to cause the issue. If I set it to be the Ipv4 address of the machine, then curling localhost fails and curling the ipv4 address works (still not working for ipv6 though).
I got similar issue, change your interface to ::0 which supports both ipv4 and ipv6 address.
My code looks like below
IO(Http) ? Http.Bind(service, interface = "::0", port = 8080)
More : https://groups.google.com/forum/#!topic/spray-user/0kPXN1XVe0E

Resources