I have a python script hosted on a remote server. Lets say the URL given by the hosting site is "myproject.host.com". The following is a part of the script:
import json import socket from flask import Flask from flask import request from flask import make_response app=Flask(__name__) # domain given by noip.com, forwarded port ip = ('abc.noip.org', 9050) # used to find device's global IP address, and modify the variable ip accordingly @app.route('/findMyIP',methods=['GET']) def findMyIP(): global ip mip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr) print(mip) ip = (mip,9050) return mip @app.route('/webhook',methods=['GET']) def webhook(data = 'Test Message'): # I am using UDP protocol sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) sock.sendto(data.encode(),ip) sock.close() return 'data sent'
I have port forwarded my router to access a device on the local network via the internet.
Lets say that the domain given by noip.com is abc.noip.org, and the forwarded port is 9050.
With this setup, I am able to access my device without any issue.
My aim is to access the device using its global IP address, without having to set up port forwarding every time I use a different router, or when I use a hotspot.
I tried doing this:
-> From the device, I connect to "myproject.host.com/findMyIP". This usually shows the device IP to be of the form 10.xx.xx.xxx.
-> I try communicating to the device using the IP address obtained from the above step.
But I am not able to get it to work. What am I missing here?