How to run Liclipse/Pydev debugger over internet? - python

I have a remote development Linux machine (with own IP address) in a VPS provider. I also have my machine that connects to internet via a router. I want a Django process in the server to connect to a pydev debug server on my machine.
I use pydev debugger, this configuration tells django at any host to connect to the given host/port where the debugger is running.
pydevd.settrace('localhost', port=5678, suspend=False)
How to connect to the VPS from my desktop? NAT is impossible since the router and DHCP is not in my control. VPN seems feasible but complicated.

I think the best way to resolve it in this case would be doing a port forwarding through ssh -- I don't have any specific instructions for that, but google has plenty ;)

Related

Python DHCP enabled disabled check

I'm using Python 3.8.5 currently on windows, but the script should run also on linux and on macOS.
I'm creating UDP server and a client and have establish communication between them via multicast.
The client does not know from advanced the IP of the server so it is a "discovery tool" that will let me know information about the server ones it has received the data. -This is working-
On the server I'm using netifaces to get information about the interfaces.
The server sends information to the client such as IP address, mask, gateway. -information that I get from netifaces and is working-.
Example of data I get:
Now to the issue:
The python server can have a static IP or can be connected to a DHCP server -in case that is connected to a DHCP server I will not have access to the DHCP server-.
I wish to know when the DHCP is enabled or disable on the python server so I can send this as a flag to the client together with the rest of the information.
The idea is for the client to know that the IP that he's connecting to can change and he may lose connection and will need to start the discovery tool once more.
Because the user will not know in advanced if the python server is connected to a DHCP server or wil know the IP address of the python server or have access to the python server command line or configuration, using ip addr show, ipconfig, ifconfig and other commands before connecting is not an option.
I have seen that people use scrapy for DHCP communications but it seems that it does not solves what I wish to accomplish.
I do no need to configure the DHCP, just detect if my python server IP is static or dynamic.
I have search for over 4 days and have not found a possible solution.
I'm not asking to have the solution in silver spoon just to be pointed on the right direction.
**EDIT: I forgot to mention that the python server will be running on Ubuntu 16.04 and 20.04.
This will depend on your operating system setup. For example, here's a related question on how to detect whether DHCP is enabled in Ubuntu.

Django - Host a website on a Lan Network

I've been working on a website for the past month, and now its time for me to host the django website onto a private server. Is there a detailed method on how I'm supposed to host the website onto a specific IP address assigned to my system?
This is my first time dealing with hosting a server and i dont know much about it.
Also, once i host it, How do i change the link from being the IP address to an actual link like "12345678.com" or something like that?
(The website should be hosted in such a way that only the people who are in the same network/lan connection should have access to the website.)
I have wamp on the system and the system has a Windows Server OS (if this info helps)
you can run your codes with manage command like this
python manage.py runserver 0.0.0.0:8000
but its strongly recommended to run your code with a web server like nginx or apache read this tutorial to run your site on a linux server
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-ubuntu-14-04
on windows you can use IIS but its not recommended. its performance is not good
to use 1234567890.com instead of using server ip address you must setup a DNS server on your local network. in linux you can use bind and windows server have its own DNS server. but in your DHCP configuration you must set this DNS server as clients DNS.

Django is not available from forwarded port

I'm trying to connect to my website from another node on another network. If the nodes are in the same network, i can connect to the website without a problem.
I've forwarded port for ssh and Django (8000), I also have apache ready on port 9080.
ssh and apache ports work fine when connecting to them from external ip address, Django does not for some reason.
First, i tried to run the server on port 8000:
python manage.py runserver 0.0.0.0:8000
This works completely fine when connecting from the node that is in the same network as the server, but for some reason, whenever i try to access it from external ip address, the connection is refused.
To make sure it was Django, I also tried running the server on the same port as Apache (9080), although, i didn't expect "errorless" response, since i knew that port was occupied. But there was no change at all, I was still getting the same Apache page that i would get before.
I also tried allowing port 8000 on firewall:
sudo ufw allow 8000/tcp
But pretty sure this is not the problem, since this Debian came without any firewall.
I also tried to empty ALLOWED_HOSTS in settings, but there was no progression.
It seems like Django has no effect for external connections, what could be the reason?
I also struggle to understand the purpose of other http web server platforms in this case (e.g Apache, Nginx), Isn't Django creating a webserver itself along with its custom wsgi?
Firewall is not the problem, neither is the web server, then may the problem be caused by the Django itself? Maybe it is outer firewall?
It is not clear how you are configuring Apache to forward requests to Django, it seems like you are treating those as two independent components. If you want to use a web server in front of Django (recommended for production envs), you need to configure both Apache and Django.
Then, as you are running django in dev mode (python manage.py runserver 0.0.0.0:8000), you should reach Django in http://server_ip:8000 regardless of Apache, perhaps there is another firewall blocking the connection. Use tracert / traceroute to find out where the connection is blocked.
FInally, for production environments, it is recommended to use a web server in front of Django to increase security and performance. See the docs for further information.
My guess is that you have another firewall blocking the port. You opened the local firewall using ufw, but there may be an outer firewall.
python manage.py runserver 0.0.0.0:8000 starts correctly? If so, keep an eye in the log.
Inside the server, do a request wget http://localhost:8000. The request should be logged
If you can reach Apache in port 9080 from outside the server, you can:
Use nmap to find the opened / closed / filtered ports in the server to find if there is another firewall inbetween.
Configure Apache to forward requests to Django, although this does not solve the problem
In your question you say that you have forwarded port for ssh and Django. What exactly is this? Are you sure that you have not misconfigured your ssh server to listen in port 8000?

python, django, vagrant and access error on windows host machine

Well, I'm trying to access a python server (for django development) in a Virtual Box VM via vagrant, but I can't connect with it in my windows browsers. I'll try to describe all the things I've done to make this work, so maybe it can help you guys.
My configurations:
I set my vagrant file to allow connections in port 8000 (guest and host)
I have disabled my windows firewall.
I have turned off the firewall on the VM
I have disabled all chrome extensions (including addblock)
I have disabled almost all apps in my windows to minimize the chances that some program could use port 8000
I have unchecked "automatically detect settings" and "use a proxy server for your lan" in the lan settings (windows internet options), then done the ip /release, ip /renew and rebooted my machine
Yes, the python server is running well on the vm
I tried the default 127.0.0.1:8000 (no success) and changed to 0.0.0.0:8000 using the command "python manage.py runserver 0.0.0.0:8000", but still ... :(
I have a nginx server in the vm running well for my php apps in port 80, and i cant access them with no problems
I use pycharm for python development and it starts my server normally in the vm either using 127.0.0.1:8000 or 0.0.0.0:8000
I think that's it, but the error persists, I can't access my python server in my ip 192.168.56.101 in port 8000, this ip is my private network on the vm that runs good with nginx.
But the result is always the same
Whenever I try access http://192.168.56.101:8000/ all my browsers (IE, Firefox, Chrome) cannot complete the request, in Chrome the error is ERR_CONNECTION_TIMED_OUT
Thanks in advance for any help !
My problem was the firewall rules. I dont really need it since its a development environment, so I delete all the rules in /etc/iptables/rules.v4 and save the file. That solve it all. Tks.

how do i configure python/flask for public access with windows firewall

We have developed an app in python and are using flask to expose its api via http requests.
all this on WINDOWS -
Everything works ok and we have tested in-house with no problems and we are now trying to use the app in the real world - we have gotten our IT dept to give us a public facing ip/port address (forwarded through a firewall ??) and now we can't access the server/app at all.
After a bit of digging, we've found the problem has something to do with the Windows Firewall configuration, when its on it won't work, when its off everything is fine.
the flask app code is run like so: app.run(debug=False, host='0.0.0.0', port=8080)
the port 8080 is setup in the Firewall Exceptions as is python.exe in the Program Exceptions
netstat -a shows the app is sitting there awaiting connection.
If I try to access the site though chrome I get the error: ERR_CONNECTION_TIMED_OUT.
With the firewall on i'm never seeing any "hits" come through to the app at all.
Is there some other configuration I'm missing?
Many thanks.
When running Flask from a windows machine with a firewall I open a port with the following commands:
netsh firewall add portopening TCP 8080 "MyAppName"
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=in action=allow protocol=TCP localport=8080
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=out action=allow protocol=TCP localport=8080
It work for me. Is it too much? I don't know as I am not a Firewall guru :(
When running as a service the program running the service is not python.exe but rather pythonservice.exe. You will have to add that to the allowed programs in the Windows Firewall Setup. In my case it is located under C:\Python33\Lib\site-packages\win32\pythonservice.exe.

Categories

Resources