Server(PHP) to Local Machine(Python) request - python

I have a php web server
In my local machine i wrote python code to send its private ip(device ip), wifi mac address & public ip (ie. routers ip address in my case my phone) via api. when the the python program hit a api written on the server, php will store the addresses in database.
so the server has the addresses of the local machine.
there are some data in the local machine which it need to send to the server. but i can't send it by hitting api from python to the server because the requirement is the server needs to pull data from client machine when required (will do manually by web user).
so is there any way where server can send request to the python code(written in local machine) with the help of device ip, routers public ip, device mac address.
i know that i can use websocket to do this, but is there any other way??
can i write api in python and the server hit the api when needed, its just my thought i don't know much about networking

Related

SSL issue when trying to communicate with Python webserver on Raspberry PI by using a Progressive Web App

I'm trying to create a measurement device which can be controlled with a smart phone.
My situation
The places where I'm using the device don't have any internet connection available.
The measurement device uses a Raspberry PI, which creates a local WiFi network to communicate with the smart phone.
There is a Python webserver running on the RPI.
The smart phone has a PWA installed to send commands to the RPI's webserver.
The PWA is hosted on GitHub Pages (uses HTTPS by default).
After installation the PWA is supposed to work without an internet connection (just uses the RPI WiFi).
My goal is to successfully send requests to the Python webserver on the RPI by using the PWA on my smart phone.
My issue
When fetching the Python webserver within the PWA, I receive a Mixed Content error because the PWA is hosted on HTTPS (and also requires HTTPS) but the Python server is not.
When I tried using a self signed certificate created with OpenSSL, I receive a ERR_CERT_AUTHORITY_INVALID error.
I tried to use Let's Encrypt, but CertBot requires an actual domain. I only have an IP adress, which is the RPI's IP within its own WiFi network.
What should I do?
I fixed my issue by registering a free .tk domain pointing to 127.0.0.1 (localhost) and using Certbot from Let's Encrypt to create a SSL Certificate.
To validate the domain with Certbot I've used the TXT record validation.
In order to make use of the domain without an internet connection I've added a DNS record with the same .tk domain pointing to localhost inside the dnsmasq config file of the RPI.
My python webserver then uses the cert file to establish serving over HTTPS so the SPA on my mobile device won't throw an error when requesting data.

Connecting Server to Client using Socket Programming

I am trying to connect two computer using socket library with python. One of the system is my local system and another is an instance in AWS. The one hosted in AWS has its own public address. And my local system only has private ip address (192.168.10.1). I am able to establish connection from my local system to system in AWS. But not the vice versa.
Is it possible to connect from AWS system to local system (here local system should be listening for other incoming connection)
You need to configure your router to forward requests from AWS to the computer on your network. It would be good practice to set your local computer with a static IP address or use DHCP reservation to ensure that the address doesn't change.
warning: You will also need to ensure your connection is secure mostly likely using a combination of authentication, authorisation and encryption. Forwarding ports exposes your device to the entire world.

how can I post to api running on remote desktop?

I'm creating a python flask api on remote desktop and running it on localhost of remote desktop.
Is there anyway I can access this api from my local machine?
We are working in a team and I want to share this with my team members, but this is confidential and not to be deployed on open server.
We want to post and get the result with every member's local machine from api runnnig on remote desktop.
Both of our local machines and remote desktop are windows10.
Sorry for being abstract but I'm searching for any way out. Thanks.
Well, you should open your way to this API. You'll have to set up a VPN or IP address filter in the server so you can access the server from your network while still have it secured on the Internet. You can also setup a simpler proxy if you prefer it. I'll not cover the details on how to setup a VPN or proxy since it can get pretty extensive, but a Google search will help you out find the best alternative for you.
AFAIK, the Remote Desktop Protocol does not allow for any kind of VPN. However, if you can switch to TeamViewer, it does have an easy to setup VPN system that will allow you to get into the network with few configuration. Once a VPN is configured, it will work like if you were in the same network as the server, so from there you can access your API from your host machine by just going to the IP address of the server.
Do notice the security policies of whoever owns the server, since you can get into trouble if you don't have permission to enable some access from the outside. Security goes always in front of comfort.
Short term solution:
Firstly download ngrok for your operating system.
For debugging and testing purposes you can expose a secure tunnel connection to your API by running this command in your command prompt / terminal.
ngrok http <PORT_NUMBER>-host-header="localhost:<PORT_NUMBER>"
Where PORT_NUMBER is the port number in which your flask application is running.
Example if your flask application is running at port 5000 then simply execute this command:
ngrok http 5000 -host-header="localhost:5000"
Running this will give you two hostnames one with HTTP and other a secure HTTPS connected by a tunnel like this for a duration of 8 hours after which the command needs to again re-run.
Which you can call remotely
Long term solution:
Deploy flask application using FastCGI
or
To a cloud infrastructure provider like Microsoft Azure which gives readymade templates for flask applications.

How to host flower on a remote machine that can also be accessed over the internet

I am trying to run flower on a remote ubuntu server. However, I am unsure on what address/port to run it on so that other people can login (I have the basic auth set up) and check their celery workers. The ubuntu server is actually an EC2 instance, so am I supposed to use its private or public ip address? Do I just open any standard port? In their docs, they use their example setup with http://localhost/5555 but I do not think that will work if flower will be running on a remote server. Any advice?
Flower runs on 5555 by default- which port are you running it on? The private IP is only available if the requests are coming from INSIDE your amazon network, so probably public.
So, if my guesses are right, you want to create an AWS security rule allowing traffic from "anywhere" to port 5555 and apply that to your instance, and then access that instance using its public ip like
http://50.31.10.99:5555

Rackspace connecting to a server using Pyrax in python

I have recently started using pyrax, the python binding for the Rackspace API. I have a test account on Rackspace and a server running there. Using my username and api_key I can authenticate and list all the servers found in that region.
How do I connect to a particular server given its name, server id, IPv4 address, IPv6 address, flavor etc.?
Pyrax is specifically used to interact with the Rackspace Cloud API in provisioning the resources.
A different library would be required if you wanted to connect to the server via SSH. Check out something like http://www.lag.net/paramiko/

Categories