Upgrade yt-dlp to version 2022.11.11
[sunny256-utils.git] / netgraph
blob8db0665234134dbdd44f05a273a80f2dd7b1c163
1 #!/usr/bin/env perl
3 #=======================================================================
4 # netgraph
5 # File ID: d2d6c67a-48f9-11e0-a72d-c3b2f04a5e88
6 # Generate GraphViz DOT files from traceroute(1) output
8 # Character set: UTF-8
9 # ©opyleft 2011– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'colour' => "",
25 'debug' => 0,
26 'help' => 0,
27 'style' => "",
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 Getopt::Long::Configure("bundling");
38 GetOptions(
40 "colour|c=s" => \$Opt{'colour'},
41 "debug" => \$Opt{'debug'},
42 "help|h" => \$Opt{'help'},
43 "style|s=s" => \$Opt{'style'},
44 "verbose|v+" => \$Opt{'verbose'},
45 "version" => \$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'debug'} && ($Debug = 1);
50 $Opt{'help'} && usage(0);
51 if ($Opt{'version'}) {
52 print_version();
53 exit(0);
56 my @Hosts = ();
58 while (<>) {
59 my $Line = $_;
60 if ($Line =~ /^\s*.*?(\d+\.\d+\.\d+\d+\.\d+)\s/) {
61 push(@Hosts, sprintf("\"%s\"", $1));
64 my $attr = "";
65 $attr .= $Opt{'colour'} ? " color=\"$Opt{'colour'}\"" : "";
66 $attr .= $Opt{'style'} ? " style=\"$Opt{'style'}\"" : "";
67 $attr =~ s/^\s+//;
68 length($attr) && ($attr = " [$attr]");
69 print(join(" -> ", @Hosts),
70 $attr,
71 ";\n"
74 sub print_version {
75 # Print program version {{{
76 print("$progname v$VERSION\n");
77 # }}}
78 } # print_version()
80 sub usage {
81 # Send the help message to stdout {{{
82 my $Retval = shift;
84 if ($Opt{'verbose'}) {
85 print("\n");
86 print_version();
88 print(<<END);
90 Usage: $progname [options] [file [files [...]]]
92 Options:
94 -c X, --colour X
95 Use colour X on this graph.
96 -h, --help
97 Show this help.
98 -s X, --style X
99 Use line style X. Can contain the values
100 solid (default)
101 dashed
102 dotted
103 bold
104 -v, --verbose
105 Increase level of verbosity. Can be repeated.
106 --version
107 Print version information.
108 --debug
109 Print debugging messages.
112 exit($Retval);
113 # }}}
114 } # usage()
116 sub msg {
117 # Print a status message to stderr based on verbosity level {{{
118 my ($verbose_level, $Txt) = @_;
120 if ($Opt{'verbose'} >= $verbose_level) {
121 print(STDERR "$progname: $Txt\n");
123 # }}}
124 } # msg()
126 sub D {
127 # Print a debugging message {{{
128 $Debug || return;
129 my @call_info = caller;
130 chomp(my $Txt = shift);
131 my $File = $call_info[1];
132 $File =~ s#\\#/#g;
133 $File =~ s#^.*/(.*?)$#$1#;
134 print(STDERR "$File:$call_info[2] $$ $Txt\n");
135 return("");
136 # }}}
137 } # D()
139 __END__
141 # Plain Old Documentation (POD) {{{
143 =pod
145 =head1 NAME
149 =head1 SYNOPSIS
151 [options] [file [files [...]]]
153 =head1 DESCRIPTION
157 =head1 OPTIONS
159 =over 4
161 =item B<-h>, B<--help>
163 Print a brief help summary.
165 =item B<-v>, B<--verbose>
167 Increase level of verbosity. Can be repeated.
169 =item B<--version>
171 Print version information.
173 =item B<--debug>
175 Print debugging messages.
177 =back
179 =head1 BUGS
183 =head1 AUTHOR
185 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
187 =head1 COPYRIGHT
189 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
190 This is free software; see the file F<COPYING> for legalese stuff.
192 =head1 LICENCE
194 This program is free software: you can redistribute it and/or modify it
195 under the terms of the GNU General Public License as published by the
196 Free Software Foundation, either version 2 of the License, or (at your
197 option) any later version.
199 This program is distributed in the hope that it will be useful, but
200 WITHOUT ANY WARRANTY; without even the implied warranty of
201 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
202 See the GNU General Public License for more details.
204 You should have received a copy of the GNU General Public License along
205 with this program.
206 If not, see L<http://www.gnu.org/licenses/>.
208 =head1 SEE ALSO
210 =cut
212 # }}}
214 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :