Change policy about how we handle generated files
[amule.git] / src / utils / scripts / id2ip
blob93e37678387e3600c043c6f0a13414accb41dc4b
1 #!/usr/bin/awk -f
3 # This file is part of the aMule project.
5 # Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
6 # Copyright (c) 2004-2011 xmb ( http://xmb.ath.cx )
7 # Copyright (c) 2004-2011 Jacobo Vilella (Jacobo221)
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either
12 # version 2 of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 ##########################################
25 # #
26 # Convert eD2k HighID numbers to IPs #
27 # #
28 ##########################################
29 # #
30 # Original code: xmb #
31 # Further code improvements: Jacobo221 #
32 # #
33 # Contact: IRC @ irc.freenode.net/#awk #
34 # jacobo221 at @amule dot org #
35 # #
36 ##########################################
37 # #
38 # This code is distributed under terms #
39 # of the GPL license #
40 # http://www.gnu.org/copyleft/gpl.html #
41 # #
42 ##########################################
43 # #
44 # Usage: id2ip.awk ID <...> #
45 # #
46 ##########################################
48 BEGIN {
50 if (ARGC == 1) {
51 printf "Usage: id2ip.awk ID <...>\n"
52 exit
55 while (num = ARGV[++i]) {
57 if (ARGV[i] < 16777216) {
58 printf "%s -> LowID\n",ARGV[i]
59 } else if (ARGV[i] > 256*256*256*256) {
60 printf "%s -> Invalid IP\n",ARGV[i]
61 } else {
63 m = 256 * 256 * 256
65 for (c = 0; m > 0; c++ ) {
66 IP[c] = int(num / m)
67 num -= IP[c] * m
68 m /= 256
71 printf "%s -> %d.%d.%d.%d\n", ARGV[i], IP[3], IP[2], IP[1], IP[0]