Cannot connect to python SimpleHTTPServer but can connect to apache - python

I was setting up a public Ipython Notebook in my remote Ubuntu 12.04 server according to http://ipython.org/ipython-doc/1/interactive/public_server.html#notebook-public-server, but when all was done, I cannot connect to it via both chrome and safari (in both https and http modes), I got timeout error in chrome, safari told me server isn't responding. So I tested the system by setting up following simple python server:
python -m SimpleHTTPServer
And the same error occured. I also checked the port with sudo netstat -anltp|grep :8000, which seems fine:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 22683/python
What surprises me is that I have the apache running and holding websites just fine (I also try to turn it off when configuring python server but that didn't help). Can anyone give me a clue what might be wrong in the Ubuntu server and how I should debug it?
I have found the issue: it turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.

It turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.

Related

How to use WHOIS queries from python script when port 43 is likely not accessible

Im very new to network programming and faced a following problem:
Im working on VMware CentOS7 virtual machine on Windows10 host.
My script should send WHOIS queries and parse their output (e.g. expiration date).
However, an attempt to send a query leads to a connection error:
>>>import whois
>>>whois.query('google.com')
WhoisCommandFailed: connect: Network is unreachable
I tried to whois from terminal, but error was the same.
When i tried to use whois directly from Windows, which hosts virtual machine, the error seemed to look same as well (connection timeout).
As i found out, it was most likely related to access to port 43. I created rules (for in and out) for Windows firewall for this port by a guide , but error still persisted.
It looks like access to this port was blocked by ISP (however ping command is working).
To sum up, I got two questions there:
1) (less important) How to check if port 43 is blocked by firewall either by ISP?
2) (most important) Is it possible somehow to reconfigure WHOIS for usage of another port (i.e. 23) for sending queries by Python script?
Unfortunately, ISP security policy doesn't allow them to open 43 port.
Mostly ISP doesn't block any port but yes, this is not 100% true.
Testing connection:
run tcpdump (install command: yum install tcpdump) command on CentOS: tcpdump -peni any tcp and port 43
You have to see lines with the following text: 192.168.1.1.57350 > 192.34.234.30.43 where 192.34.234.30 IP address means the remote whois server.
Try to telnet to remote server's TCP/43 port: telnet 192.34.234.30 43
You should see the following:
Trying 192.34.234.30...
Connected to 192.34.234.30.
Escape character is '^]'.
If you can`t see context like that and you get back prompt immediately you will a firewall rule somewhere what is block connection. I recommend to switch off firewall temporarily and test again.
You cannot change port number, because it is configured on the remote side, on the server.
Can CentOS7 server communicate towards the internet? In example can you install packages?
Is there any router between windows machine and ISP?

Django centos server not receiving requests

I just deployed my Django project to a local CentOS server for testing. The problem is that after I run my server like: 192.168.1.4 (server ip), and run in port:3001 and then I send a request from another computer on the same LAN this requests are not being received by the server.
Local request from the server to the server are working fine.
Also:
ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
Django: 2.1
CentOs: 7
The command netstat shows that indeed the port is listening.
The port has already been opened in the router.
Even when netstat showed that the port was open, it was closed in the server. I managed t open it with the following command:
sudo firewall-cmd --zone=public --add-port=3001/tcp --permanent
sudo firewall-cmd –reload
I hope this helps anyone else having similar issues.
The default IP address, 127.0.0.1, is not accessible from other machines on your network.
To access your machine from other machines on the network, use its own IP address 192.168.1.4 or 0.0.0.0.
python manage.py runserver 0.0.0.0:8000

Can't access python server started in Windows 7 from another PC

I have two computers in the same enterprise network. The one with Windows XP (IP 192.168.101.96) and the other with Windows 7 (IP 192.168.101.98).
If I start Django project on PC with Windows XP (python manage.py runserver 192.168.101.96:8001), I can easily access it from Windows 7 PC with browser.
But the opposite way doesn't work. If I start Django project on PC with Windows 7, I can't access it from Windows XP PC.
The same situation is with command python -m SimpleHTTPServer 8001.
I tried to add a rule for external connections on TCP port 8001 in Windows firewall settings. Also I tried to add python.exe to firewall exceptions, but nothing seems to work...
It should be noted that when I start Django server and execute NETSTAT -p tcp -ano command, I can see line:
TCP 192.168.101.98:8001 0.0.0.0:0 LISTENING 6920
But nevertheless, nothing work. What can be the source of the problem?
for access to another computer server , server must be run on port 80.
you must run django server on port 80
python manage.py runserver 0.0.0.0:80
then access with type ip in the browser without post number :
http://192.168.101.98/
good luck
The problem was in ESET Endpoint Security special firewall. It's "automatic mode" blocks traffic without any promt to user. The problem can be solved by adding special rule to this firewall or changing it's main policy to "interactive mode" for example.

Can't connect to remote django server port 80

I'm having an issue running and connecting to my python django server on a windows 2012 server. To run the server I use command: python manage.py 0.0.0.0:80. This results in an error below
[Error 10013]: an attempt was made to access a socket in a way forbidden by its access permissions
I've tried running the command prompt as an administrator with no change. For reference, I am able to run the server on port 8000 but then I cannot connect to the port remotely. I have turned off firewalls as well so that is probably not the issue.
While it is preferable to run the django on port 80, I am trying to get this working on any port.
Port 80 (and many other ports) is reserved by Windows Server. Checkout this https://serverfault.com/questions/633179/cant-make-confluence-run-on-port-80-with-windows-server-2012-r2,
You may want to google "Windows Server Reserved port" for more info and a way to "unreserve" it.

How to properly open Port 8888 in Ubuntu under VirtualBox?

I am working on a Python Flask application in Ubuntu under VirtualBox, run from OSX. Now I want to connect my python application from OSX (the host OS). I am using a NAT networking, and already read about Port Forwarding (which I think it's very easy). But, somehow if I test my application using Google Chrome, try to open http://localhost:8888 (my server in Ubuntu listen to port 8888), chrome return with Server return no response (or kinda)
I have issue the following command in OSX terminal : `VBoxManage modifyvm "Ubuntu 12.0.4 LTS" --natpf1 "fikrposdc,tcp,,8888,,8888". And my python application already listening to port 8888, :
* Running on http://127.0.0.1:8888
I've read that in Ubuntu, by default there is no firewall. So, I try to netstat, but issuing `netstat | grep LISTEN didn't gave any output...
Is there something that I missed?
`
Wooops!
Having read related question, I found this question with the exact same problem. And I modify my code to run the application :
app.run(host="0.0.0.0", port=8888)
Now I can continue my work!
Thanks

Categories

Resources