4 ## This file is part of the aMule Project
6 ## Copyright (c) 2004-2008 Angel Vidal ( kry@amule.org )
7 ## Copyright (c) 2006-2008 aMule Project ( http://www.amule-project.net )
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
30 print "You must specify at least one ip.\n";
31 $exit_with_help = "true";
34 if ($exit_with_help) {
35 die "Usage: kadnodescreate.pl [hash:ip:TCPport:UDPport:type]+\n";
39 print "Creating nodes.dat...\n";
42 open(MET
," > nodes.dat");
45 my $contactcount = $#ARGV + 1;
47 print "\tContacts: " . $contactcount . "\n";
49 print MET
&int32_string
($contactcount);
58 my $contactnumber = 0;
59 foreach $contact (@ARGV) {
61 if ($contact =~ /^(.*):(.*):(.*):(.*):(.*)$/) {
63 $hash = &check_hash
($1);
65 die "Malformed hash, can't continue: " . $1 . "\n";
70 die "Malformed ip, can't continue: " . $2 . "\n";
73 my $tcpport = &check_port
($3);
75 die "Malformed tcp port, can't continue: " . $3 . "\n";
78 $udpport = &check_port
($4);
80 die "Malformed udp port, can't continue: " . $4 . "\n";
83 $type = &check_type
($5);
85 die "Malformed contact type, can't continue: " . $5 . "\n";
89 print "\t\tAdding Contact " . $contactnumber . ":\n";
90 print "\t\t\tHash : " . $1 . "\n";
91 print "\t\t\tIP : " . $ip . "\n";
92 print "\t\t\tTCPPort : " . $tcpport . "\n";
93 print "\t\t\tUDPPort : " . $udpport . "\n";
94 print "\t\t\tType : " . $type . "\n";
96 print MET
&hash_string
($1) .
98 &int16_string
($tcpport) .
99 &int16_string
($udpport) .
102 die "Malformed contact line, can't continue: " . $contact . "\n";
106 print "Closing nodes.dat\n\n";
114 if ($_[0] =~ /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/) {
115 $ipresult = ($1*16777216) + ($2*65536) + ($3*256) + $4;
122 if ($_[0] =~ /^([0-9]{1,5})$/) {
132 if ($_[0] =~ /^([0-9])$/) {
140 if ($_[0] =~ /^([A-Z]|[0-9]|[a-z]){32}$/) {
153 &byte_string
($_[0] % 256) . &byte_string
($_[0] / 256);
157 &int16_string
($_[0] % 65536) . &int16_string
($_[0] / 65536);
161 &int32_string
($_[0] % 4294967296) . &int32_string
($_[0] / 4294967296);
166 my $final_string = "";
168 $final_string = $final_string . &byte_string
(hex(substr($_[0],$i,2)));