Computer NetworksNETWORKS

Get IPv4 Address from python even with vpn on

Download this code from https://codegive.com
Certainly! Obtaining the IPv4 address using Python, even when a VPN is active, can be achieved by leveraging external services or modules that provide this information. In this tutorial, I’ll guide you through using the requests library to fetch your public IPv4 address, and we’ll also consider scenarios where a VPN might be in use.
If you haven’t installed the requests library, you can do so using the following command:
Now, let’s create a Python script that retrieves the public IPv4 address:
In this example, we are using the ipify service to get the public IPv4 address. This service provides a simple JSON API to retrieve your public IP address.
If you are using a VPN, the public IP address obtained using the method above will reflect the IP address assigned by your VPN service. If you want to get the local (internal) IP address assigned by your network or VPN, you can use the socket library:
Keep in mind that the local IP address obtained using socket will be the IP address assigned to your machine within the local network or VPN, which may not be visible on the internet.
This tutorial provides you with a simple method to retrieve both the public and local IPv4 addresses using Python, even when a VPN is active. Make sure to handle errors gracefully and customize the code according to your specific use case.
ChatGPT

source

ipv4

Alice AUSTIN

Alice AUSTIN is studying Cisco Systems Engineering. He has passion with both hardware and software and writes articles and reviews for many IT websites.