# IP Fetcher
<!-- License and PyPI Version Buttons -->
<p>
<a href="https://opensource.org/licenses/MIT">
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT">
</a>
<a href="https://pypi.org/project/ip-fetcher/" rel="nofollow">
<img alt="PyPI - Version" src="https://img.shields.io/pypi/v/ip-fetcher?label=Newest%20version&link=https%3A%2F%2Fpypi.org%2Fproject%2Fip-fetcher%2F">
</a>
<img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/ip-fetcher?label=Total%20downloads%20in%20month">
</p>
`IPFetcher` is a Python library designed to fetch, analyze, and monitor IP addresses. It includes functionality for fetching public and private IPs, checking whether an IP is public or private, scraping IP data from websites, and logging this information.
## Features
- **Fetches Public IP Address**: Retrieves the public IP address of the user.
- **Retrieves Private IP Address**: Retrieves the private IP address of the user.
- **Checks IP Type**: Determines if a given IP address is IPv4 or IPv6.
- **Detects Proxy or VPN**: Checks if a given IP address is associated with a known proxy or VPN.
- **Saves IPs to a File**: Stores public or private IP addresses in a file for later use.
- **Reads IPs from a File**: Reads previously stored IP addresses from a file.
- **Fetches Geolocation Data**: Provides geolocation information for a given IP address.
- **Scrapes IP Information**: Extracts additional IP information from websites.
- **Monitors IP Addresses**: Continuously pings and fetches location data for an IP address at a set interval.
- **Command-Line Interface**: Provides a CLI for quick access to the library's functionalities.
## Installation
To install the package, use:
```bash
pip install ip_fetcher
```
## Changelog
### 0.3.4.2 (2024-09-18)
- **Added Geolocation Lookup**: Added function to fetch geolocation data for an IP address.
- **Added IP Scraping**: Added functionality to scrape additional IP information from websites.
- **Enhanced Monitoring**: Improved IP address monitoring with pinging and location fetching.
- **Updated Error Handling**: Refined error handling for IP fetching and file operations.
### 0.3.4.1 (2024-09-16)
- **Fixed Bugs**: Addressed various bugs from previous releases.
### 0.3.4 YANKED (2024-09-16)
- **Python 3.6+ Support**: Updated compatibility to Python `3.6` or later.
- **Refactored f-strings**: Changed f-strings to `.format()` to support older versions of Python `(3.3+)`.
- **New IP Saving and Loading Feature**: Added functionality to save public and private IP addresses to a file and read them back.
- **Improved Version Check**: Automatically checks for the latest version on PyPI when the package is imported.
### 0.3.3 (2024-09-15)
- **Updated** **`setup.py`** **Requirements**: Changed Python version requirement to `>=3.9.7`.
- **Improved CLI**: Enhanced error handling and command functionality; fixed issues from versions [0.3.2](https://pypi.org/project/ip-fetcher/0.3.2/) and [0.3.2.9](https://pypi.org/project/ip-fetcher/0.3.2.9/).
- **Created Changelog Section**: Added a changelog.
## Usage
Here are some examples of how to use the `ip_fetcher` library:
### Fetching the Public IP
To get your public IP address:
```python
from ip_fetcher import get_public_ip
public_ip = get_public_ip()
print("Public IP: {}".format(public_ip))
```
### Fetching the Private IP
To get your private IP address:
```python
from ip_fetcher import get_private_ip
private_ip = get_private_ip()
print("Private IP: {}".format(private_ip))
```
### Checking IP Type
To check if an IP address is IPv4 or IPv6:
```python
from ip_fetcher import is_ipv4, is_ipv6
ip_address = "192.168.1.1"
if is_ipv4(ip_address):
print("{} is an IPv4 address.".format(ip_address))
elif is_ipv6(ip_address):
print("{} is an IPv6 address.".format(ip_address))
else:
print("{} is not a valid IP address.".format(ip_address))
```
### Checking If IP is Public or Private
To check if an IP address is public or private:
```python
from ip_fetcher import is_public_or_private
ip_status = is_public_or_private("192.168.1.1")
print(ip_status) # Output: "192.168.1.1 is Private."
```
### Checking for Proxy or VPN
To check if an IP address is associated with a proxy or VPN:
```python
from ip_fetcher import detect_proxy_or_vpn
ip_address = "8.8.8.8"
proxy_data = detect_proxy_or_vpn(ip_address)
print(proxy_data)
```
### Monitoring IP
To monitor an IP address:
```python
from ip_fetcher import monitor_ip
ip_to_monitor = "8.8.8.8"
try:
monitor_ip(ip_to_monitor, interval=60) # 60 seconds interval between checks
except KeyboardInterrupt:
print("Monitoring stopped.")
```
### Scraping IP Data
To scrape an IP address data from a website:
```python
from ip_fetcher import scrape_ip_data
website_to_scrape = "https://example.com"
scraped_data = scrape_ip_data(website_to_scrape)
print(scraped_data)
```
### IP Geolocation Lookup
To lookup and IP address geolocation:
```python
from ip_fetcher import geolocation_lookup
ip_to_lookup = "8.8.8.8"
geo_data = geolocation_lookup(ip_to_lookup)
print(geo_data)
```
### Saving IP Addresses to a File
You can save the public or private IP to a file for later use:
```python
from ip_fetcher import get_public_ip, get_private_ip, store
public_ip = get_public_ip()
private_ip = get_private_ip()
# Save the IP addresses to a file
store(public_ip, "ip_addresses.txt")
store(private_ip, "ip_addresses.txt")
print("IP addresses saved to ip_addresses.txt")
```
### Reading IP Addresses from a File
You can load and display the saved IPs from a file:
```python
from ip_fetcher import read
ips = read("ip_addresses.txt")
for ip in ips:
print(ip)
```
### Reading a Specific IP Address from a File
You can load and display a specific IP address from a file:
```python
from ip_fetcher import read_specific
public_ip = read_specific("public_ip_address", "ip_addresses.txt")
if public_ip:
print("Stored Public IP: {}".format(public_ip))
else:
print("Public IP address not found in the file.")
```
### Command-Line Interface (CLI)
After installing the package, you can use the command-line interface to access the library's functionalities directly from the terminal.
### Fetch Public IP
```bash
ip-fetcher --public
```
### Fetch Private IP
```bash
ip-fetcher --private
```
### Fetch Both Public and Private IPs
```bash
ip-fetcher --public --private
```
**Note:** Ensure that the CLI tools are correctly set up after installation. If you encounter issues, verify that your `PATH` environment variable includes the directory where `ip-fetcher` is installed.
Raw data
{
"_id": null,
"home_page": null,
"name": "ip-fetcher",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "IP address, public IP, private IP, network utilities, Python library, CLI tool, IP fetching, IP",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/70/cb/97683b2fe9877adf7f9554cfb4c348f3cc2deeb6c6009f24421d31532838/ip_fetcher-0.3.4.2.tar.gz",
"platform": null,
"description": "# IP Fetcher\r\n\r\n<!-- License and PyPI Version Buttons -->\r\n<p>\r\n <a href=\"https://opensource.org/licenses/MIT\">\r\n <img src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License: MIT\">\r\n </a>\r\n\r\n <a href=\"https://pypi.org/project/ip-fetcher/\" rel=\"nofollow\">\r\n <img alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/ip-fetcher?label=Newest%20version&link=https%3A%2F%2Fpypi.org%2Fproject%2Fip-fetcher%2F\">\r\n </a>\r\n <img alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/ip-fetcher?label=Total%20downloads%20in%20month\">\r\n</p>\r\n\r\n`IPFetcher` is a Python library designed to fetch, analyze, and monitor IP addresses. It includes functionality for fetching public and private IPs, checking whether an IP is public or private, scraping IP data from websites, and logging this information.\r\n\r\n## Features\r\n\r\n- **Fetches Public IP Address**: Retrieves the public IP address of the user.\r\n- **Retrieves Private IP Address**: Retrieves the private IP address of the user.\r\n- **Checks IP Type**: Determines if a given IP address is IPv4 or IPv6.\r\n- **Detects Proxy or VPN**: Checks if a given IP address is associated with a known proxy or VPN.\r\n- **Saves IPs to a File**: Stores public or private IP addresses in a file for later use.\r\n- **Reads IPs from a File**: Reads previously stored IP addresses from a file.\r\n- **Fetches Geolocation Data**: Provides geolocation information for a given IP address.\r\n- **Scrapes IP Information**: Extracts additional IP information from websites.\r\n- **Monitors IP Addresses**: Continuously pings and fetches location data for an IP address at a set interval.\r\n- **Command-Line Interface**: Provides a CLI for quick access to the library's functionalities.\r\n\r\n## Installation\r\n\r\nTo install the package, use:\r\n\r\n```bash\r\npip install ip_fetcher\r\n```\r\n## Changelog\r\n\r\n### 0.3.4.2 (2024-09-18)\r\n- **Added Geolocation Lookup**: Added function to fetch geolocation data for an IP address.\r\n- **Added IP Scraping**: Added functionality to scrape additional IP information from websites.\r\n- **Enhanced Monitoring**: Improved IP address monitoring with pinging and location fetching.\r\n- **Updated Error Handling**: Refined error handling for IP fetching and file operations.\r\n\r\n### 0.3.4.1 (2024-09-16) \r\n- **Fixed Bugs**: Addressed various bugs from previous releases.\r\n\r\n### 0.3.4 YANKED (2024-09-16)\r\n\r\n- **Python 3.6+ Support**: Updated compatibility to Python `3.6` or later.\r\n- **Refactored f-strings**: Changed f-strings to `.format()` to support older versions of Python `(3.3+)`.\r\n- **New IP Saving and Loading Feature**: Added functionality to save public and private IP addresses to a file and read them back.\r\n- **Improved Version Check**: Automatically checks for the latest version on PyPI when the package is imported.\r\n\r\n### 0.3.3 (2024-09-15)\r\n\r\n- **Updated** **`setup.py`** **Requirements**: Changed Python version requirement to `>=3.9.7`.\r\n- **Improved CLI**: Enhanced error handling and command functionality; fixed issues from versions [0.3.2](https://pypi.org/project/ip-fetcher/0.3.2/) and [0.3.2.9](https://pypi.org/project/ip-fetcher/0.3.2.9/).\r\n- **Created Changelog Section**: Added a changelog.\r\n\r\n## Usage\r\n\r\nHere are some examples of how to use the `ip_fetcher` library:\r\n\r\n### Fetching the Public IP\r\n\r\nTo get your public IP address:\r\n\r\n```python\r\nfrom ip_fetcher import get_public_ip\r\n\r\npublic_ip = get_public_ip()\r\nprint(\"Public IP: {}\".format(public_ip))\r\n```\r\n\r\n### Fetching the Private IP\r\n\r\nTo get your private IP address:\r\n\r\n```python\r\nfrom ip_fetcher import get_private_ip\r\n\r\nprivate_ip = get_private_ip()\r\nprint(\"Private IP: {}\".format(private_ip))\r\n```\r\n\r\n### Checking IP Type\r\n\r\nTo check if an IP address is IPv4 or IPv6:\r\n\r\n```python\r\nfrom ip_fetcher import is_ipv4, is_ipv6\r\n\r\nip_address = \"192.168.1.1\"\r\n\r\nif is_ipv4(ip_address):\r\n print(\"{} is an IPv4 address.\".format(ip_address))\r\nelif is_ipv6(ip_address):\r\n print(\"{} is an IPv6 address.\".format(ip_address))\r\nelse:\r\n print(\"{} is not a valid IP address.\".format(ip_address))\r\n```\r\n\r\n### Checking If IP is Public or Private\r\n\r\nTo check if an IP address is public or private:\r\n\r\n```python\r\nfrom ip_fetcher import is_public_or_private\r\n\r\nip_status = is_public_or_private(\"192.168.1.1\")\r\nprint(ip_status) # Output: \"192.168.1.1 is Private.\"\r\n```\r\n\r\n### Checking for Proxy or VPN\r\n\r\nTo check if an IP address is associated with a proxy or VPN:\r\n\r\n```python\r\nfrom ip_fetcher import detect_proxy_or_vpn\r\n\r\nip_address = \"8.8.8.8\"\r\n\r\nproxy_data = detect_proxy_or_vpn(ip_address)\r\nprint(proxy_data)\r\n```\r\n\r\n### Monitoring IP\r\n\r\nTo monitor an IP address:\r\n\r\n```python\r\nfrom ip_fetcher import monitor_ip\r\n\r\nip_to_monitor = \"8.8.8.8\"\r\n\r\ntry:\r\n monitor_ip(ip_to_monitor, interval=60) # 60 seconds interval between checks\r\nexcept KeyboardInterrupt:\r\n print(\"Monitoring stopped.\")\r\n\r\n```\r\n\r\n### Scraping IP Data\r\n\r\nTo scrape an IP address data from a website:\r\n\r\n```python\r\nfrom ip_fetcher import scrape_ip_data\r\n\r\nwebsite_to_scrape = \"https://example.com\"\r\n\r\nscraped_data = scrape_ip_data(website_to_scrape)\r\nprint(scraped_data)\r\n```\r\n\r\n### IP Geolocation Lookup\r\n\r\nTo lookup and IP address geolocation:\r\n\r\n```python\r\nfrom ip_fetcher import geolocation_lookup\r\n\r\nip_to_lookup = \"8.8.8.8\"\r\n\r\ngeo_data = geolocation_lookup(ip_to_lookup)\r\nprint(geo_data)\r\n```\r\n\r\n### Saving IP Addresses to a File\r\n\r\nYou can save the public or private IP to a file for later use:\r\n\r\n```python\r\nfrom ip_fetcher import get_public_ip, get_private_ip, store\r\n\r\npublic_ip = get_public_ip()\r\nprivate_ip = get_private_ip()\r\n\r\n# Save the IP addresses to a file\r\nstore(public_ip, \"ip_addresses.txt\")\r\nstore(private_ip, \"ip_addresses.txt\")\r\n\r\nprint(\"IP addresses saved to ip_addresses.txt\")\r\n```\r\n\r\n### Reading IP Addresses from a File\r\n\r\nYou can load and display the saved IPs from a file:\r\n\r\n```python\r\nfrom ip_fetcher import read\r\n\r\nips = read(\"ip_addresses.txt\")\r\nfor ip in ips:\r\n print(ip)\r\n```\r\n\r\n### Reading a Specific IP Address from a File\r\n\r\nYou can load and display a specific IP address from a file:\r\n\r\n```python\r\nfrom ip_fetcher import read_specific\r\n\r\npublic_ip = read_specific(\"public_ip_address\", \"ip_addresses.txt\")\r\nif public_ip:\r\n print(\"Stored Public IP: {}\".format(public_ip))\r\nelse:\r\n print(\"Public IP address not found in the file.\")\r\n```\r\n\r\n### Command-Line Interface (CLI)\r\n\r\nAfter installing the package, you can use the command-line interface to access the library's functionalities directly from the terminal.\r\n\r\n### Fetch Public IP\r\n\r\n```bash\r\nip-fetcher --public\r\n```\r\n\r\n### Fetch Private IP\r\n\r\n```bash\r\nip-fetcher --private\r\n```\r\n\r\n### Fetch Both Public and Private IPs\r\n\r\n```bash\r\nip-fetcher --public --private\r\n```\r\n\r\n**Note:** Ensure that the CLI tools are correctly set up after installation. If you encounter issues, verify that your `PATH` environment variable includes the directory where `ip-fetcher` is installed.\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library to fetch public and private IP addresses.",
"version": "0.3.4.2",
"project_urls": null,
"split_keywords": [
"ip address",
" public ip",
" private ip",
" network utilities",
" python library",
" cli tool",
" ip fetching",
" ip"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1a32d35a14713013d8966f8226b43c84a9a91a1831aa3a1b73333ad4806d5c74",
"md5": "487d7dad7bfb3c67629ce9ee4b0ba44d",
"sha256": "334d8d48550206bcf1e68bdf2fe92955ef2b0ec4317bbf708b9fead3efd68294"
},
"downloads": -1,
"filename": "ip_fetcher-0.3.4.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "487d7dad7bfb3c67629ce9ee4b0ba44d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 8553,
"upload_time": "2024-09-18T21:08:03",
"upload_time_iso_8601": "2024-09-18T21:08:03.344984Z",
"url": "https://files.pythonhosted.org/packages/1a/32/d35a14713013d8966f8226b43c84a9a91a1831aa3a1b73333ad4806d5c74/ip_fetcher-0.3.4.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "70cb97683b2fe9877adf7f9554cfb4c348f3cc2deeb6c6009f24421d31532838",
"md5": "22044d211e1d63c9b9700f030ad5d08e",
"sha256": "f392808cb10729595347f5ea2409563136ec0e7e2412800bc1e5a02e5f62ab6f"
},
"downloads": -1,
"filename": "ip_fetcher-0.3.4.2.tar.gz",
"has_sig": false,
"md5_digest": "22044d211e1d63c9b9700f030ad5d08e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8003,
"upload_time": "2024-09-18T21:08:04",
"upload_time_iso_8601": "2024-09-18T21:08:04.670916Z",
"url": "https://files.pythonhosted.org/packages/70/cb/97683b2fe9877adf7f9554cfb4c348f3cc2deeb6c6009f24421d31532838/ip_fetcher-0.3.4.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-18 21:08:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ip-fetcher"
}