Skip to content

added: function to sort public and private IPv4 #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.2
Choose a base branch
from

Conversation

BeardedInfoSec
Copy link

This function takes in both public and private IPv4 addresses and returns the public IPs. This prevents sending internal IPv4 address for enrichment

This function takes in both public and private IPv4 addresses and returns the public IPs. This prevents sending internal IPv4 address for enrichment
@HarlodHolt
Copy link

You could use ipaddress library and is global and or other boolean checks, something like:

import ipaddress

Define an IP address (IPv4 or IPv6)

ip1 = ipaddress.ip_address("8.8.8.8")
ip2 = ipaddress.ip_address("192.168.1.1")
ip3 = ipaddress.ip_address("2001:4860:4860::8888")
ip4 = ipaddress.ip_address("fe80::1")

Check if the IP addresses are global

print(f"{ip1} is global: {ip1.is_global}") # Expected: True
print(f"{ip2} is global: {ip2.is_global}") # Expected: False (private IP)
print(f"{ip3} is global: {ip3.is_global}") # Expected: True
print(f"{ip4} is global: {ip4.is_global}") # Expected: False (link-local address)

https://docs.python.org/3/library/ipaddress.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants