Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket 'No route to host' error

I have a connection which is behind a restrictive firewall which only allows HTTP(S) access through a proxy (10.10.1.100:9401). The IP address I get is dynamic and the subnet mask is 255.255.255.255 (I know, weird!).

I tried to write a simple Python socket program to connect to the proxy in order to send some HTTP requests:

import socket

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
s.connect(( "10.10.1.100", 9401 ))
s.send("GET /index.html HTTP/1.1\r\nHost: aorotos.com\r\n\r\n")
d = s.recv(1024)
print d
s.close()

I get an exception (113, "No route to host") during the connect. Now here is the weird part—I can browse the web using these same proxy settings, and if check the currently connected sockets via netstat -tna I see an ACTIVE connection to 10.10.1.100:9401.

I tried a simple command like export http_proxy='10.10.1.100:9401' && wget aorotos.com/index.html and even that works! If I enable the debug option (-d) in wget, I can even get the socket's file descriptor.

I went through the wget source code, and from what I can see it too uses a normal connect statement and does not set any special socket options (I'll go through it more throughly later). I've tried the same code in C, and it too fails.

The routing table provided via route is

Destination Gateway     Genmask     Flags   Metric Ref  Use Iface
default      *          0.0.0.0       U     0      0     0  gprs0

Does anyone have any idea what might be wrong?

EDIT: Currently my IP is 10.16.82.250. And that is all that is there in the route output. If you're interested my external IP is 203.8.8.2.

ifconfig gprs0 -

gprs0     Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.17.221.94  P-t-P:10.17.221.94  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP  MTU:1400  Metric:1
          RX packets:1832 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1844 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10 
          RX bytes:1878364 (1.7 MiB)  TX bytes:224746 (219.4 KiB)

EDIT 2 : I landed up installing tcpdump and going through it's manual, and finally installing wireshark ( I'm on my N900 ) only to realize, from the packet dump, that I've been using the port 4901 instead of 9401 in both in C program and the python script! Doh! I blame the small screen and, well, myself.

Is there any way to close this question with a "I'm an idiot" or something? :P Sorry for taking up your time! ( I've spent over a week on this. I can't believe I went through most of wget's source code! )

like image 978
Vishesh Handa Avatar asked Sep 20 '10 14:09

Vishesh Handa


1 Answers

I am not sure what the issue is but try using Wireshark. This will at least let you see what is going on at the network level. There should be enough info from the Wireshark packet logs to diagnose your problem.

like image 128
doron Avatar answered Oct 21 '22 12:10

doron