#!/usr/bin/perl

# This script is used to telnet to the DLink DSL300T
# and update the ip_conntrack_max setting so it'll
# work for longer if BitTorrent is being used

# JimmyGulp - 07/01/2005 - james@jimmygulp.co.uk

use Expect;

# Set variables :)
$hostname = "192.168.1.1";
$username = "root";
$password = "admin";
	#Note 'admin' is the default password, change
	#this setting to the password you use

########## Change NOTHING beyond Here #############

&main();

sub main {
	&login();
	&change_settings();
}

sub login {
	$rlogin=Expect->spawn("telnet $hostname");
	$rlogin->expect(30,"login:") || die "Never got usename \n";
	print $rlogin "$username\r";
	$rlogin->expect(30,"word:") || die "Mever got password prompt \n";
	print $rlogin "$password\r";
}

sub change_settings {
	$rlogin->expect(30,"#") || die "Never got prompt :(\n";
	print $rlogin "cd /proc/sys/net/ipv4/netfilter/\r";
	$rlogin->expect(30,"#") || die "Never got prompt :(\n";
	print $rlogin "echo \"65535\" > ip_conntrack_max\r";
	$rlogin->expect(30,"#") || die "Something went wrong when we updated the modem\n";
}
