Skip to content
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

dnsping: output with timestamps needed #58

Open
webernetz opened this issue Feb 15, 2019 · 5 comments
Open

dnsping: output with timestamps needed #58

webernetz opened this issue Feb 15, 2019 · 5 comments

Comments

@webernetz
Copy link
Contributor

Hey Babak.

While using dnsping to troubleshoot a DNS server I really need a timestamp (date + time with even milliseconds) to verify at what time the server failed or came back again. Could you add such an option to display a timestamp for every response?

Cheers
Johannes

@thomasmerz
Copy link

Why don't you use ts from linux package moreutils?

$ dnsping -c 4 -w 1 -s 185.253.5.9 github.com|ts
Mar 07 17:23:35 dnsping DNS: 185.253.5.9:53, hostname: github.com, proto: UDP, rdatatype: A, flags: RD
Mar 07 17:23:35 55 bytes from 185.253.5.9: seq=1   time=27.269 ms
Mar 07 17:23:36 55 bytes from 185.253.5.9: seq=2   time=21.999 ms
Mar 07 17:23:37 55 bytes from 185.253.5.9: seq=3   time=24.639 ms
Mar 07 17:23:38 55 bytes from 185.253.5.9: seq=4   time=19.659 ms
Mar 07 17:23:39
Mar 07 17:23:39 --- 185.253.5.9 dnsping statistics ---
Mar 07 17:23:39 4 requests transmitted, 4 responses received, 0% lost
Mar 07 17:23:39 min=19.659 ms, avg=23.391 ms, max=27.269 ms, stddev=3.289 ms

Or this:

$ dnsping -c 4 -w 1 -s 185.253.5.9 github.com|awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
2023-03-07 17:24:06 dnsping DNS: 185.253.5.9:53, hostname: github.com, proto: UDP, rdatatype: A, flags: RD
2023-03-07 17:24:06 55 bytes from 185.253.5.9: seq=1   time=21.522 ms
2023-03-07 17:24:07 55 bytes from 185.253.5.9: seq=2   time=20.262 ms
2023-03-07 17:24:08 55 bytes from 185.253.5.9: seq=3   time=21.523 ms
2023-03-07 17:24:09 55 bytes from 185.253.5.9: seq=4   time=19.022 ms
2023-03-07 17:24:10
2023-03-07 17:24:10 --- 185.253.5.9 dnsping statistics ---
2023-03-07 17:24:10 4 requests transmitted, 4 responses received, 0% lost
2023-03-07 17:24:10 min=19.022 ms, avg=20.582 ms, max=21.523 ms, stddev=1.198 ms

Might this help and solve your "problem"?

@webernetz
Copy link
Contributor Author

Nice approach, thx.

(Though I would like a direct option within dnsping, similar to "ping -D ".)

@farrokhi
Copy link
Owner

farrokhi commented Mar 8, 2023

@webernetz would you please point me to your reference ping implementation? Unfortunately ping has no "standard" implementation and I see -D doing different things on different platforms. But I like adding this feature seamlessly. Just want to see how others are implementing this, from a UX perspective.

@edeka-spatt
Copy link

Hi Babak,
this would be a nice and needed addition to the dnsping.py script. I tried it myself using the logging module.
Here is some sample code I used for adding timestamps and Log File output quick & dirty:


import logging
...
    # Logging
    current_datetime = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
                        encoding='utf-8',
                        level=logging.INFO,
                        handlers=[
                            logging.FileHandler(str(current_datetime)+'_'+dnsserver+'_'+qname+'.log'),
                            logging.StreamHandler()
                        ])

...
    logging.info("%s DNS: %s:%d, hostname: %s, proto: %s, type: %s, flags: [%s]" %
          (__progname__, dnsserver, dst_port, qname, proto_to_text(proto), rdatatype,
           dns.flags.to_text(request_flags)))



@webernetz
Copy link
Contributor Author

Hey Babak. I don't have a "reference ping implementation" to be honest. I sometimes use the "normal" ping out of Ubuntu for example with the -D option to show at least some timestamps. This gives (note the very first [column with the Unixtime output]:

weberjoh@h2877111:~$ ping -D heise.de PING heise.de(redirector.heise.de (2a02:2e0:3fe:1001:302::)) 56 data bytes [1710770512.119462] 64 bytes from redirector.heise.de (2a02:2e0:3fe:1001:302::): icmp_seq=1 ttl=53 time=11.3 ms [1710770513.119322] 64 bytes from redirector.heise.de (2a02:2e0:3fe:1001:302::): icmp_seq=2 ttl=53 time=11.4 ms [1710770514.123749] 64 bytes from redirector.heise.de (2a02:2e0:3fe:1001:302::): icmp_seq=3 ttl=53 time=14.8 ms [1710770515.124475] 64 bytes from redirector.heise.de (2a02:2e0:3fe:1001:302::): icmp_seq=4 ttl=53 time=14.5 ms ^C --- heise.de ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3002ms rtt min/avg/max/mdev = 11.286/12.982/14.782/1.641 ms

However, to my mind, it would be even better if a timestamp would show the date and time, such as @thomasmerz proposed it

Or this:

$ dnsping -c 4 -w 1 -s 185.253.5.9 github.com|awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
2023-03-07 17:24:06 dnsping DNS: 185.253.5.9:53, hostname: github.com, proto: UDP, rdatatype: A, flags: RD
2023-03-07 17:24:06 55 bytes from 185.253.5.9: seq=1   time=21.522 ms
2023-03-07 17:24:07 55 bytes from 185.253.5.9: seq=2   time=20.262 ms
2023-03-07 17:24:08 55 bytes from 185.253.5.9: seq=3   time=21.523 ms
2023-03-07 17:24:09 55 bytes from 185.253.5.9: seq=4   time=19.022 ms
2023-03-07 17:24:10
2023-03-07 17:24:10 --- 185.253.5.9 dnsping statistics ---
2023-03-07 17:24:10 4 requests transmitted, 4 responses received, 0% lost
2023-03-07 17:24:10 min=19.022 ms, avg=20.582 ms, max=21.523 ms, stddev=1.198 ms

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

No branches or pull requests

4 participants