Comments (2)
Hi @cldeluna 👋, I'm glad you like this library!
You recommend not using FQDNs. May I as why? Most of my inventory files use FQDNs which is why I ask.
FQDNs are not discouraged except for the multiping
function (see #44). In short, icmplib provides several out-of-the-box functions including the multiping
function. This function can resolve FQDNs or hostnames like the other ones. However, if one of them is not resolvable, the whole function stops (and raises an NameLookupError
), which can be problematic depending on the context.
Example:
from icmplib import multiping, NameLookupError
domains = [
'google.com',
'dns.google.com',
'this-domain-does-not-exist.tld',
'github.com',
'one.one.one.one'
]
try:
hosts = multiping(domains, privileged=False)
for host in hosts:
if host.is_alive:
print(f'{host.address} is up!')
else:
print(f'{host.address} is down!')
except NameLookupError as err:
print(err)
Will output:
The name 'this-domain-does-not-exist.tld' cannot be resolved
To control exceptions more precisely, the same library provides a resolve
function that you can use to resolve FQDNs and hostnames to IPs, which you can then pass to the multiping
function.
Example:
from icmplib import multiping, resolve, NameLookupError
domains = [
'google.com',
'dns.google.com',
'this-domain-does-not-exist.tld',
'github.com',
'one.one.one.one'
]
addresses = []
for domain in domains:
try:
address = resolve(domain)[0]
addresses.append(address)
except NameLookupError:
print(f'{domain} does not exist!')
hosts = multiping(addresses, privileged=False)
for host in hosts:
if host.is_alive:
print(f'{host.address} is up!')
else:
print(f'{host.address} is down!')
Will output:
this-domain-does-not-exist.tld does not exist!
216.58.213.174 is up!
8.8.8.8 is up!
140.82.121.3 is up!
1.1.1.1 is up!
Would it be possible to add reverse lookup (get FQDN from IP address)?
icmplib focuses on the ICMP protocol and not on the DNS protocol 😉 Python already includes great tools to do this like socket.getnameinfo
.
Example:
>>> import socket
>>> socket.getnameinfo(('8.8.8.8', 0), 0)[0]
'dns.google'
from icmplib.
Hi @cldeluna!
Thank you for your huge donation! ❤️ It's really gratifying to see that this project is appreciated.
Sorry for the delay, I'm a little overwhelmed right now. I only saw your donation recently.
Would you like me to put your name on the README to thank you?
from icmplib.
Related Issues (20)
- Enhancement: class Host to return a dict with it's data HOT 1
- The regular time.time() function does not work well in Windows, rtt = 0 HOT 2
- Can only receive the last hop using traceroute on Windows HOT 3
- The future of icmplib
- traceroute only provides last hop HOT 1
- samsung.com - Packetloss 100.0% HOT 1
- Add the ability to set the DF flag and get MTU size feedback from the ICMP protocol.
- Actual license is unclear: is it LGPLv3 or LGPLv3+? HOT 1
- Add reply payload retrieval and checking HOT 1
- The traceroute under ipv6 only displays the last hop HOT 5
- Whats the difference between icmpLib and the icmpLibv2(forked from IcmpLib) ? HOT 3
- Use predefined socket either SOCK_DGRAM / SOCK_RAW on every invocation of ping API HOT 1
- After upgrading to ubuntu 22.04 sysctl changes are needed again HOT 3
- Feature: auto-detect best "privileged" setting HOT 3
- Feature: unprivileged traceroute HOT 4
- Error on running very basic Ping command HOT 1
- Running traceroute only returns final hop HOT 1
- Make payload more flexible HOT 2
- Unnecessary last `sleep()` in `multiping()` HOT 2
- Feature: Async traceroute
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from icmplib.