4 ## This file is part of the aMule Project
6 ## Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org )
7 ## Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
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
29 print "You must specify at least one ip.\n";
30 $exit_with_help = "true";
33 if ($exit_with_help) {
34 die "Usage: kadnodescreate.pl [hash:ip:TCPport:UDPport:type]+\n";
38 print "Creating nodes.dat...\n";
41 open(MET
," > nodes.dat");
44 my $contactcount = $#ARGV + 1;
46 print "\tContacts: " . $contactcount . "\n";
48 print MET
&int32_string
($contactcount);
57 my $contactnumber = 0;
58 foreach $contact (@ARGV) {
60 if ($contact =~ /^(.*):(.*):(.*):(.*):(.*)$/) {
62 $hash = &check_hash
($1);
64 die "Malformed hash, can't continue: " . $1 . "\n";
69 die "Malformed ip, can't continue: " . $2 . "\n";
72 my $tcpport = &check_port
($3);
74 die "Malformed tcp port, can't continue: " . $3 . "\n";
77 $udpport = &check_port
($4);
79 die "Malformed udp port, can't continue: " . $4 . "\n";
82 $type = &check_type
($5);
84 die "Malformed contact type, can't continue: " . $5 . "\n";
88 print "\t\tAdding Contact " . $contactnumber . ":\n";
89 print "\t\t\tHash : " . $1 . "\n";
90 print "\t\t\tIP : " . $ip . "\n";
91 print "\t\t\tTCPPort : " . $tcpport . "\n";
92 print "\t\t\tUDPPort : " . $udpport . "\n";
93 print "\t\t\tType : " . $type . "\n";
95 print MET
&hash_string
($1) .
97 &int16_string
($tcpport) .
98 &int16_string
($udpport) .
101 die "Malformed contact line, can't continue: " . $contact . "\n";
105 print "Closing nodes.dat\n\n";
113 if ($_[0] =~ /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/) {
114 $ipresult = ($1*16777216) + ($2*65536) + ($3*256) + $4;
121 if ($_[0] =~ /^([0-9]{1,5})$/) {
131 if ($_[0] =~ /^([0-9])$/) {
139 if ($_[0] =~ /^([A-Z]|[0-9]|[a-z]){32}$/) {
152 &byte_string
($_[0] % 256) . &byte_string
($_[0] / 256);
156 &int16_string
($_[0] % 65536) . &int16_string
($_[0] / 65536);
160 &int32_string
($_[0] % 4294967296) . &int32_string
($_[0] / 4294967296);
165 my $final_string = "";
167 $final_string = $final_string . &byte_string
(hex(substr($_[0],$i,2)));