I'm trying to get the server that comes with Flask to run inside my network but I can't get it to work properly, it simply doesn't load.
For test purposes I'm running a simple hello world app using app.run(host='0.0.0.0') and it loads fine from the host but I get a timeout when connecting from another machine.
I tried forcing other ports using app.run(host='0.0.0.0', port='80') but I had no success. Using the IP explicitly like app.run(host='10.X.X.X') didn't help either.
However I don't think it is a network problem since I can successfully do a ping 10.X.X.X from the second machine and get the response.
The question: Can it maybe have anything to do with the IP being in the format "10.X.X.X"? What else can be causing this behavior?
Related
Im trying to get an RPC connection to my bitcoin core to work, but no matter what I try, it keeps failing.
I'm running Win 10 and have bitcoin core qt V0.21 running.
I have tried several options to get the RPC connection to work. I tried several docker container like btc-rpc-explorer but those keep on failing with a ECONNREFUSED error. Worried about some IP problem with docker, I also tried running different python scripts (like this on: https://pypi.org/project/bitcoinrpc/) but that also gives an exception indicating that no rpc connection is possible.
So, it must be my bitcore node then, right? So I tried many different bitcoin.conf configurations without luck. My latest:
server=1
rpcallowip=0.0.0.0/0
rpcbind=127.0.0.1
rpcbind=0.0.0.0
rpcport=8332
rpcuser=myuser
rpcpass=mypass
txindex=1
Just trying to open it up as much as possible.
I also tried running bitcoind on commandline in stead of bitcoin-qt gui. The commandline output shows me that it takes the correct bitcoin.conf file. So thats okay. But what is wrong???
server=1
rpcallowip=127.0.0.1
rpcport=8332
rpcuser=myuser
rpcpass=mypass
txindex=1
If you are doing your rpc calls within localhost this conf file should be enough.
I would bind to 0.0.0.0 only if you need to query from an external ip.
rpcallowip=0.0.0.0/0 is also insecure
This question already has an answer here:
Unable to connect to Flask local server
(1 answer)
Closed 2 years ago.
Whenever I am running flask python main file, I am getting this ""**Running on http://0.0.0.0:5000/**". When I tap the url I am getting "this site can't be reached". Can anyone explain and solve this issue please?
The URL that it is displaying is not reachable because 0.0.0.0 is just a placeholder. You need to figure out which address it is actually listening on. If you are trying to reach a server from the same machine, try http://localhost:5000/; if you are accessing it over the network, you need to figure out what addresses the server is actually reachable by.
It's not always obvious from within the server itself, though the output of ifconfig or similar probably works at least within the same local network. Try https://whatismyip.com/ or a similar service from within the server if you need to see its publicly routable address (assuming still that there is no firewall or etc in place which is blocking this port from public access).
Please try adding host parameter:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(host='localhost') #Or change to your ip, such as '192.168.30.56'
Console out put:
Running on http://localhost:5000/ (Press CTRL+C to quit)
Configure Flask dev server to be visible across the network
Meaning it runs on my PC's IP address visible to the entire internet and arbitrary Python code can be run via my Flask app?
The direct answer is: yes, it is unsafe. But then again, so is driving a car or eating at a new restaurant with bad reviews.
The point is evaluating the risk. Things to consider:
Are you launching this on a home network? In which case, your router almost certainly comes with its own firewall (and I only don't make the assertion because I can't possibly cover every single case). The server will not be accessible outside of the home network. Maybe there's a malicious housemate harbouring resent and waiting to pounce?
Are you launching on an intranet network? This would be accessible to everyone on the network. The vast majority of people won't be scanning the network for open ports, but you can't rule it out. Low risk., but it could happen that someone finds it.
Are you running this on a server with a dedicated IP (not an internal IP like 10.0.0.x or 192.168.x.x)? Is the particular port you're running on open to the wider internet e.g. no firewall or special rules for that port? In which case, expect to get requests.
Can someone landing on the site actually do something malicious? The whole point of having a web server is for other people to access it. If discovering your app is enough to be a real concern then it's just broken and you should be testing your fears on localhost.
I am writing web app, where I would like to:
Display LOCAL stream from webcam - it means, that I want to stream video from server (I do not want to open webcam of client)
Read QR Codes and list them in text box
These two were already achieved but! I came across some unexpected behaviour. Functionality that I have described is working perfectly, but only on localhost. I want to deploy it, so it could be accessible via different computer (it is meant to be used on a robot).
So to describe my architecture: I am using Jetson TX2 as a server (webcam is connected here). I am using Django web framework, django-channels, daphne as a web server and ngingx as a proxy. I am running daphne and background process in supervisor.
I am using worker (background process) to capture frames from webcam and send it via redis to the web backend.
So when I run it on localhost everything work as expected. When I set Debug to FALSE and I add Jetson's IP to ALLOWED_HOSTS and try to access the web from different computer this happens:
I can see, that webcam is accessed because the webcam light turns on. I put some QR code in front of the webcam and the code appears in the textbox on web! BUT the video is not there (when ALLOWED_HOSTS contains localhost video IS there). Output of background process which collects the camera frames gives following error:
libv4l2: error setting pixformat: Device or resource busy
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline)
in cvCaptureFromCAM_GStreamer, file /home/nvidia/prototype/opencv/opencv-3.4.0/modules/videoio/$
VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)):raised OpenCV exception:
/home/nvidia/toyota_prototype/opencv/opencv-3.4.0/modules/videoio /src/cap_gstreamer.cpp:890: error: (-2)$
in function cvCaptureFromCAM_GStreamer
I will not post whole code here, since I do not know where exactly is the problem. Does anyone have an idea where the problem could be?
Thank you for your help!
So, I figured it out. In my html template I had one line, where I was linking to the stream address:
<img src="http://127.0.0.1:8000/webcam-stream">
I think, now you all know, where the problem was. I needed to change the IP to HOST address.
This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 5 years ago.
I am trying to create a Flask app (using Python 2.7) that I can access from across networks, as the title says. I have managed to get the app up and running, and it works successfully all across the Wi-Fi network of my computer where the app is running. I have been accessing it using my internal IP address and port 8000. Whenever I connect from my phone, which is connected to the Wi-Fi, it works. However, when I switch to cellular data and connect from that, it doesn't work, and instead says "took too long to respond". The code for the app itself is as follows:
from flask import Flask, render_template
from GradeScraper import scrapeforgrades
app = Flask(__name__)
#app.route('/')
def home():
scrapeforgrades()
return render_template("Grades.html")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)
GradeScraper is just a web scraper I have written, to be called in the app. I don't believe that file is the reason for my problems.
I have also tried connecting to the app from my external IP address, but it says "refused to connect". I went to this StackOverflow page I found, and the answer said something about security settings. I didn't understand at all how to change those. The person who asked the question commented at the end "I played around with security settings and finally got it working" which leads me to the conclusion that I should do the same. Unfortunately, I have no idea how to do that. Could anybody point me in the right direction? I'll provide any and all extra information needed.
Thanks,
Me
For a start probably (hopefully!) your router is blocking all incoming connections; even if it didn't, your computer's "internal IP Address" (the one you connect to via WiFi) is not only unreachable from outside your network, but also unroutable (in other words, your cellular's operator network has no idea how to find it).
You should look for a NAT (network Address translation) function in your router, pick an external port (any port will do - I recommend one above 1024) and map that port to your computer's IP address, port 8000.
IF you don't know what you're doing, that is however A Really Bad Idea - you will be immediately targeted by port scanners looking for vulnerabilities.
To expand on the topic...
your Computer's IP will be something like 192.168.1.101, while your router may be something like 192.168.1.1 - the 192.168/16 space is deemed a "private IP space" and unroutable from the "public IP" space (the one where all external services live - for example, from my location, google.com maps to 172.17.6.46.
Your phone has two radios (and thus, logically, not physically, 2 NICs): the WiFi (which will get an address from the DHCP server in your router: something like 192.168.1.102) and the LTE/4G radio (which will have an IP address of choice from your provider - something like 174.94.66.23, or, possibly, an IPv6): the former can get to your local server, but the latter can't.
Your ISP will have assigned to your router's WAN port one of these "public IPs" form its pool (they usually rotate them, unless you paid for a static IP address) - that one is what you need to find out (http://formyip.com being the easiest way) and then point to it from your phone (or an external computer or whatever).
The matter is complicated and, as mentioned, dangerous for the novice - educate yourself about routing and NAT: just be aware that opening up your network and keeping a server running on the public network is pretty scary stuff these days (I wouldn't do it, and I used to be at Google and I am now with another "large well-known" corporation :)
Alternatively, if your router allows, you could setup an OpenVPN connection: that is more secure, but an altogether other level of complexity.
Hope this helps.