IPForce is a Python library that provides HTTP adapters for forcing specific IP protocol versions (IPv4 or IPv6) during HTTP requests. It's particularly useful for testing network connectivity, ensuring compatibility with specific network configurations, and controlling which IP protocol version is used for DNS resolution and connections.
| PyPI Counter | |
| Github Stars |
| Branch | main | dev |
| CI |
| Code Quality |
- Download Version 0.1 or Latest Source
pip install .
- Check Python Packaging User Guide
pip install ipforce==0.1
Use when you need to ensure connections only use IPv4 addresses, useful for legacy systems that don't support IPv6, networks with IPv4-only infrastructure, or testing IPv4 connectivity.
import requests
from ipforce import IPv4TransportAdapter
# Create a session that will only use IPv4 addresses
session = requests.Session()
session.mount('http://', IPv4TransportAdapter())
session.mount('https://', IPv4TransportAdapter())
# All requests through this session will only resolve to IPv4 addresses
response = session.get('https://ifconfig.co/json')Use when you need to ensure connections only use IPv6 addresses, useful for modern networks with IPv6 infrastructure, testing IPv6 connectivity, or applications requiring IPv6-specific features.
import requests
from ipforce import IPv6TransportAdapter
# Create a session that will only use IPv6 addresses
session = requests.Session()
session.mount('http://', IPv6TransportAdapter())
session.mount('https://', IPv6TransportAdapter())
# All requests through this session will only resolve to IPv6 addresses
response = session.get('https://ifconfig.co/json')Warning
Current adapters are NOT thread-safe! They modify the global socket.getaddrinfo function, which can cause issues in multi-threaded applications.
Just fill an issue and describe it. We'll check it ASAP!
- Please complete the issue template
Give a ⭐️ if this project helped you!
If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-)
