is there any way to get web-app user IP address - python

In my python project I have to track user IP address and country and region, and other information, I used "https://ipapi.co/json/" for tracking the IP address, but thing is when i deploy my model(web-app) on the deployment website, it is giving me that server IP address instead who is using my web-app. when i try in my local machine it is giving my IP address. Actually, i am currently new and don't know that much about tracking IP another.
Please anyone can describe how i will achieve this thing. how to track the user of my web-app IP address instead of the deployment server IP address.
Ref- I am using streamlit sharing for the deployment it is giving me streamlit office address instead of my friend(test user) IP. I need my fried IP address when he is using the deployed web app.
Thank you sir for your consideration, a help will be great for me, am really stuck here. my project in Python.

It sounds like you're trying to get the IP from this 3rd party service from your server, which would of course return the server's IP address.
Based on a comment on the question:
I am using streamlit for creating the web app.
Based on a cursory Google search, it sounds like getting the client's IP is non-trivial in that system:
https://discuss.streamlit.io/t/i-run-a-streamlit-app-and-it-processes-some-records-based-on-client-user-input-i-want-to-log-ip-address-of-client-user-and-records-processed-by-that-user-can-you-help-please/2382
https://discuss.streamlit.io/t/how-to-get-all-ip-addresses-and-their-countries-connecting-to-a-live-streamlit-app-on-aws-ec2/2273
https://discuss.streamlit.io/t/how-to-output-client-or-remote-ip-s-to-console/832
(Based on this I would probably recommend using a different Framework/platform for building web applications. This sounds... extremely limited. But that's another matter entirely.)
The service you reference would need to be accessed from the client computer, which means accessing it from JavaScript. If that service doesn't allow CORS requests, there are other options available. Once you have the value(s) you need in JavaScript, you can send them to your server-side code via an AJAX request, a Form POST, etc.

Related

RaspberryPi access without public URL possible?

[Never worked with a RPi before, absolute noob on that field]
I want to make a desktop/mobile app to access a program on a RaspberryPi. The only task of the app is to send a command and display the received response on an UI. It's meant only for private use, but it should also work outside my local network. So as long as I have mobile internet on the phone it should be possible to access the program with the app.
Can I achieve this without using any kind of public website? I saw some tutorials that used Flask and other frameworks to do sth similar, but I want the access to be restricted to the app. There shouldn't be any URL I could type in my browser, that gives me access to a login page or sth like that.
If you know the specific term for what I am describing here or even better an article/tutorial that features it, that would be very helpful.
You need two things for that:
Make your Raspi visible to the outside world. That can typically be done by configuring port forwarding in your router. Note that this might impose a certain security risk.
Make sure you have a global DNS name for your internet access. Since the IP of your router may change frequently (depending on your ISP), you need a URL or rather, a DNS entry. There exist public DNS services that can assign a DNS entry to a dynamic IP (typically for a fee). Many routers support a protocol to configure such services.
After that, you can program an app that uses the given DNS entry to talk to your Pi.
So no, without a public URL, this is not possible, at least not over the long term. You might be able to go with the public IP of your router, but then your app may fail from one day to the next.

Detect if a mobile app user is behind a proxy

I’m building a mobile app that requires knowing the location of the user when is sending data or posting
We have a concern if the users start to utilise proxy servers.
Are there any solutions/ python libraries that can be incorporated into the mobile app to detect users faking their location?
Users can fake their location by using a VPN. Proxies actually have other usages.
Use an API which does this. You need a real-time API which you can call through request. I use Abstract API because it's reliable and free: https://www.abstractapi.com/ip-geolocation-api you need to create an account though, but it's painless.
import requests
response = requests.get("https://ipgeolocation.abstractapi.com/v1/?api_key=YOUR_KEY&ip_address=THE_IP")
print(response.content)
In the JSON response, you have a boolean in ['security']['is_vpn'] to know if the IP belongs to a VPN.
An alternative solution is to create a script yourself, which would compare your user's IP with a list of known VPNs' IPs. But it may be not easy to find and collect all VPNs IP and update them regularly.
EDIT In response to your comment:
My answer will still work with an app spoofing the GPS locations like the one you linked because a real-time API won't be affected by that.
If you plan to use the GPS data from the phone and only look for a way to detect if it's real or fake, you can compare those GPS coordinates with the coordinates given in the API response. If there is too much of a difference, you can conclude the GPS data is faked.
You can download and host VPN or proxy list in your own server and query it with app IP address to detect if one IP address is behind a VPN or proxy.
There are public web services available but I do not recommend it as the 3rd party API site might be blocking your API call if traffics is huge.

How do I make a Flask app available for my friends through port-forwarding?

So I created a simple Flask app to automate certain calculations we often have to do in math class. I'm now trying to let my friends use it too but I can't get the local port forwarding right. When I run the app I can access it from my local network but not from outside of it. (I tested that by trying to reach the web app through my phone on mobile data, and it doesn't respond.) I'm aware that ssh tunnelling is probably a better way to do this, but I still want to figure out what I'm doing wrong here.
I am very new to this and used this video as a reference: https://www.youtube.com/watch?v=jfSLxs40sIw. Here's a brief summary of the things I already tried:
I changed app.run() to app.run(host='0.0.0.0',port=5000) to make Flask respond to all public ip's.
When I now run my app I can access it from my computer via:
http://0.0.0.0:5000/
http://127.0.0.1:5000/
http://192.168.1.101:5000/
I then used freedns.afraid.org to create a subdomain flaskdries.mooo.com. When redirecting the subdomain to the latest ip-adress in the list (192.168.1.101:5000) it would always refuse to connect, even on the pc that's running the app. Using 127.0.0.1:5000 eventually did the trick for all the devices on my network (image), but still not for devices outside of my network.
I guess that's an obvious thing since my WAN ip is nowhere to be specified in this method. So if I'm correct, when someone goes to the subdomain, there is no link to my router so also not to the device running the app. The problem is that I have no clue where I should specify my WAN ip or something similar.
I noticed that when I created the subdomain the destination was automatically set to my WAN ip
(image). At first I thought simply adding :5000 would work, but unfortunately it doesn't.
As you might have noticed I am extremely new to this and don't really have any other information i can rely on apart from the internet, so any help is welcome!
Thanks in advance,
Dries
After more research I figured out that the problem was that I have a seperate modem and router. For most people one port forward inside the router is enough, but I also had to forward a port from my modem to my router. Kind of annoying that I didn't think of that earlier. Thanks to everybody for responding tho.
Hi and welcome to stack overflow.
In order to access you app from the internet you will need an external static IP that you should be able to obtain from your internet provider. You then set your domain to point to that IP. If you don't want to specify the port each time, you can run you flask app on port 80 or 443 if you want https.
Also it is probably advisable to run it behind a web server of some sorts, like nginx since app.run is only intended to be used for local development.
You are using the ip adresses of you local network.
If you have port forwarding enabled to you machine then you have to use you public ip adress.
Your router should have the public ip adress in the admin interface.
Simplifiyed explanation:
You domain shoud lead to the external IP of your router.
Your router then forwards the request to your machine via portforwading (network IP address).

ASP.net MVC: How to access project from mobile via Local Server

Back when I wanted to test my static webpages on mobile, I would set up a Local Http Server using python like.. For example, if my page is at D:/myProject/index.html, I would use command line and go to >>D:/myProject/
Then use this line,
python -m http.server
To set up localhttpserver at port 8000. Then I would access from my mobile browser like
http://192.168.XXX.XXX:8000/index.html
But I'm very new to ASP MVC Web projects and have no idea how to access it through localserver or how to set up one. Say, my project is D:/mvcProject/exampleProject.sln. I tried setting up the same way as I did on simple webprojects up to D:/mvcProject but when I access the exampleProject.sln from browser, it's showing me the codelines instead of the view.
Please do enlighten me, holy light. I, an empty cup, seek for your wisdom.
Thank you in advance!
A .sln file is for keeping together a group of projects that are part of your solution and not for defining the routing or paths. Your route that follows MVC structure is going the include your controller and a view that is tied to that controller. For example, if you have a Controller, ExampleController, and a view for that controller, ExampleDetail.cshtml,then your path will look something like:
http://localhost/Example/ExampleDetail
Please take some time to follow through an MVC tutorial, there are plenty out there.
https://learn.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started
https://www.tutorialspoint.com/asp.net_mvc/
Publish your MVC App in Local device.
Install IIS (Internet Information Service) from Control panel.
Host your app using Local ip.
than Browse your site in mobile from same network

Serve a web page that gives access to several different local web servers

I'm sure this question is easily googleable, but I can't seem to find the right query to find the answer I want.
I'm running several apps on my home server that all serve their own website for admin and info purposes. Currently I access them all from the internet using http://MyHouseServerAddress.com:8080 etc. Where 8080 is replaced with 8081, 8082 etc. for each app. They all have their own usernames and passwords and some of them use SSL
What I want is to have a single access point, e.g. http://MyHouseServerAddress.com which gives me access to each app. Each app will have a link on that page which will take you to that app's website as if it were just a page on the main site. However... I want the single access point to be password protected and SSL'd, BUT I want to remove the passwords from all the apps as they would be accessed through the single "portal" of the initial page which is password protected and SSL'd. I.e. each app would still serve on it's original port, but that port would no longer be accessible via the internet, instead any traffic from that port would be routed through the single access point.
What I'm trying to do it get a single password login, preferably via SSL to my home server which gives me access to all my other serving apps but also secures them all behind the single login.
Can this be done with a python script or a C# app for instance running some sort of proxy or port forward script? Or would running an Appache server that can redirect traffic through itself work? I'm happy to write code to solve the problem if needed.
I hope this makes sense!
I'm running W7 on my home server.
Thanks,
Max
This sounds very much like a portal with single sign-on. I haven't tried, but you might get away with implementing oauth on your sites and have the main site be the provider.
Other way would be to use soemthing like CAS.
Look at this question for options.
You can install Apache+PHP on port 80, install PHP Web Proxy on it, allow local access to your apps (so they allow access without password from localhost) and secure this gateway with .htaccess and .htpasswd, or another way.
This is most simple solution for home using. Good enterprise solution would be SSO, bad it is not simple.

Categories

Resources