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/
Related
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
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.
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.
I have hosted a python flask web application on azure virtual machine (Windows OS). When I start the python application, it gets hosted on 127.0.01:5000 i.e. localhost. I can access this in browser by providing localhost:5000 in URL. I want to access this from outside the VM machine. The problem here is Azure VMs have an internal IP and external IP.
I tried to use the external VM IP as parameter in app.run() but it throwing error and not able to host it on external IP.
app.run(HOST = “external Azure VM IP”)
It is throwing below error when trying to host on external IP.
"Error : s.bind(get_sockaddr(hostname, port, address_family))
OSError: [WinError 10049] The requested address is not valid in its context"
Is there any way I can make it work?
Also, I tried hosting it on azure web app services and I was successfully able to host there but I am not able to install external libraries like (beautifulsoup4) into flask application hosted on Azure App Services.
you need to listen on internal IP (probably better if you listen on *), not on external IP. vm is not aware of the external ip. it will get request on its internal ip, not external.
You also need to open port(s) on firewall and on Network Security Group.
ps. package management on Azure App Services
I have a working RESTful API written in python which works well in my local machine. Now I am having some serious trouble getting started with Amazon EC2.
I have managed to create an account and managed to create an instance , and lauch the instance as well. I have connected to the instance via ssh and passed by credentials.
I have the required file (app.py) on EC2. But I have no idea how to run it. Obviously if I run it from my ssh terminal, it still is a local service.
How to make it a public RESTful API?
Like a firewall, you have to open up the server's ports. You do this via adding rules to the security group while you're configuring the EC2 instance. Add the HTTP rule, and allow all IP addresses (0.0.0.0/0) to access that. See here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html#adding-security-group-rule
You can also set SSH, HTTPS, and other secure ports here (but you probably don't want everyone accessing SSH!).