Make client.HTTPConnection connect to a specific IP address - python

Is there a way to force Python's client.HTTPConnection to connect to a specific IP address? I am writing a program that checks for the presence of a file on a web server, but I want to check every single web server, and the web servers use DNS round-robin. So I am using dns.resolver.query to get a list of all of the IP addresses associated with a specific IP address, and then I am using client.HTTPConnection to connect to each one. At least, that's what I want to do, but the client.HTTPConnection doesn't seem to.
Internally, client.HTTPConnection eventually calls socket.create_connection, but I've traced the code and can't figure out a good work-around.
I've tried URL's like http://2899902734:80/ for Google as well as http://172.217.1.14 and they don't work.

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.

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

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.

How can I disable access for my flask app for people using a VPN?

Some people are trying to access my site (I believe they are hackers), and when I blocked their IP, I noticed they used VPNs to access my site again. Is there any way I can prevent people using a VPN from accessing my site?
Any help will be VERY appreciated, I've been trying this for so long.
This is how I am blocking IP addresses:
ip_ban_list = ['130.180.2.129', '109.40.2.120', '37.120.205.148', '109.201.143.78', '37.120.132.76', '37.120.132.66', '185.244.215.134', '109.42.1.48', '109.42.2.193', '172.67.16.210']
#app.before_request
def block_method():
ip = request.environ.get('REMOTE_ADDR')
if ip in ip_ban_list:
abort(403)
Thanks in advance.
VPN providers do their best to hide that their users use VPN. Every IP list will be outdated soon and if you find out a method to identify VPN / Proxy they will find way around it.
If you have a system with limited number of users, blocking all IP addresses but whitelisting ones you want to access is effective approach. But process to start using your system is harder. Of course, you can automate that process a bit, for example by adding IPs to whitelist when user register his account. But that mean that your users needs fixed IP address and consumers does not have that option. So this approach works only in B2B solutions.
Other approach would be geoblocking. You can allow access only from IP addresses which are from certain country or region. But this kind of limitations are easily worked around with VPN / Proxies.
Third approach would be to dynamically add IPs to blacklist if you notice some suspicious behavior. Easy example would be if you notice that there is multiple failed login attemps from certain IP, you block it. And there can be some other sings of malicious traffic which can trigger your dynamic ban. It would be worth to make these dynamic bans temporary, so they would expire in a few hours. This method does not identify VPN, but may prevent hacking attemps.

Changing external IP address in Python

I have a python robot that accesses internet websites and performs some tasks (using selenium and google chrome). I would like make the python code to change my external IP address every, say, 10 interactions that the code performs in the websites. Is it possible? Would you have the adequate line of code for this task?
Note that the websites that I access recognize VPN, so when I try changing my IP address through VPN, I cannot access these websites.
Thank you

Is there a way to get a list of all IP addresses and host names that I can connect to on a local network via python

Is there a way, preferably in python but command line or possibly powershell is doable for me as well, to find every possible hostname that my username and password can connect to, then temporarily connect and request system settings (OS type for example.)
Of course I want to restrict this to my local network, not attempt to connect to like google or facebook, just because I can also ping them.
The local network is very large, and may be multiple base IP addresses, not just some 192.168.1.x stuff. Between 60,000 and 100,000 devices should be connected at any given time
For clarity, I am trying to see what is within my network, based on either proxy settings or another method, then extract a small amount of data from those locations under the assumption that all of them are configured such that a user I have access to has super permission to all devices.
My apologies if the wording is unclear. Im a python dev but I am not familiar with networking almost at all. My organization just went through a restructure, and now I am being given a request to do something I've never been involved with, and network related employees are currently unavailable as they continue to try to mitigate and help fix problems with 20,000+ additional work from home.

Categories

Resources