Connect localhost database to web application​? - python

I'm very new to web development in general. I have a database on localhost that will receive requests from my Heroku web app. Can I use SimpleHTTPServer for the case? or it has to be other modules like ngrok which I don't want to use because it renames its HTTP every time it restarts or is there some way to navigate the problem?

In order for your local database to receive requests from the internet, it will need to be reachable by a public address.
One way to have a stable public address is to use a paid ngrok plan which will allow you to reserve a TCP address.
With a reserved TCP address, you can start a ngrok tunnel that will forward traffic to your local database with something like ngrok tcp --remote-addr=<your reserved TCP address> <database port>.

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.

Server is working, but not able open in browser

I am working on a Django project where I am trying to use Jquery, I used a command-:
python -m HTTP.server on my Windows PowerShell, server is started but when I trying to use the address http://0.0.0.0:8000 in my browser it is showing an error as follow-
This site can’t be reached
The webpage at http://0.0.0.0:8000/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
my firewall is allowing access.
please help.
0.0.0.0 is not a real address; it's a special value that means "listen on every IPv4 network you can listen on".
To connect, you have to specify one of those addresses.
If your browser is on the same machine as the server, you want to use the localhost address, like either of the following:
http://localhost:8000
http://127.0.0.1:8000
That 127.0.0.1 is a real address, but it's a special one meaning "the same machine I'm on, without going through the network" (and localhost is a special name for that address).
If your server is on a different machine from the browser, you have to use an IP address or name that actually maps to the server. For example, if you started the server by doing ssh 192.168.1.100 and then running it in the shell there, you'll connect like this:
http://192.168.1.100:8000
Closing the django server (ctrl + c on termial) and then restarting my computer worked for me

Accessing Python webserver remotely on Amazon EC2

I work on a project in which I need a python web server. This project is hosted on Amazon EC2 (ubuntu).
I have made two unsuccessful attempts so far:
run python -m SimpleHTTPServer 8080. It works if I launch a browser on the EC2 instance and head to localhost:8080 or <ec2-public-IP>:8080. However I can't access the server from a browser on a remote machine (using <ec2-public-IP>:8080).
create a python class which allows me to specify both the IP address and port to serve files. Same problem as 1.
There are several questions on SO concerning Python web server on EC2, but none seems to answer my question: what should I do in order to access the python web server remotely ?
One more point: I don't want to use a Python web framework (Django or anything else): I'll use the web server to build a kind of REST API, not for serving HTML content.
you should open the 8080 port and ip limitation in security croups, such as:
All TCP TCP 0 - 65535 0.0.0.0/0
the last item means this server will accept every request from any ip and port, you also
You passble need to IAM in AWS.
Aws set security permission that need to open up port so you only localhost links your webservice
aws link

Python Proxy Through SSH

I'm being trying to
Log into a server using SHH (with Paramiko)
Use that connection like a proxy and route network traffic through it and out to the internet. So say I could set it as my proxy in Urllib2, Mechanize, Firefox, etc.).
Is the second part possible or will I have to have some sort of proxy server running on the server to get this to work?
You could implement a SOCKS proxy in the paramiko client that routes connections across the SSH tunnel via paramiko's open_channel method. Unfortunately, I don't know of any out-of-the-box solution that does this, so you'd have to roll your own. Alternatively, run a SOCKS server on the server, and just forward that single port via paramiko.

Categories

Resources