Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 82 lines (70 sloc) 3.4 KB
#!/usr/bin/perl -w
use strict;
my @script = ( q[iptables -t nat -F],
q[iptables -F],
q[iptables -t nat -A POSTROUTING -o rmnet0 -j MASQUERADE],
q[iptables -t nat -A POSTROUTING -o rmnet1 -j MASQUERADE],
q[iptables -t nat -A POSTROUTING -o rmnet2 -j MASQUERADE],
q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet0 -o rndis0],
q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet1 -o rndis0],
q[iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT -i rmnet2 -o rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet0 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet1 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet2 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet3 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet4 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet5 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet6 -i rndis0],
q[iptables -A FORWARD -j ACCEPT -o rmnet7 -i rndis0],
q[ifconfig rndis0 10.100.DEVICENUM.2 netmask 255.255.255.0 up],
q[echo 1 > /proc/sys/net/ipv4/ip_forward] );
#my @devs = ( 'x', 'usb0', 'usb1', 'usb2' );
system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/all/rp_filter" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/accept_local" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/all/log_martians" );
system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/eth0/rp_filter" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/eth0/accept_local" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/eth0/log_martians" );
system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/default/rp_filter" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/default/accept_local" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/default/log_martians" );
open DEVICELIST, "$ENV{'HOME'}/android/android-sdk-linux/platform-tools/adb devices |" or die "$!";
my @serials;
while (<DEVICELIST>) {
next unless /device$/;
my ( $serial ) = ( split /\s+/, $_ )[ 0 ];
push @serials, $serial;
}
close DEVICELIST or die "$!";
for my $num (0..$#serials) {
my $device = $serials[ $num ];
my $dev_index = $num + 1;
# my $dev = $devs[ $dev_index ];
my $dev = "cell-$serials[ $num ]";
my $linemod = "setprop sys.usb.config rndis,adb";
$linemod =~ s{DEVICENUM}{$dev_index}g;
my $str = qq{./runon $device shell su -c "$linemod"};
print "$str\n";
system( $str );
print "Sleeping 5 seconds for rndis change to take effect and adb to reboot \n";
system("sleep 5");
# print ("Stop network manager to prevent autoconf \n");
# system( "sudo service network-manager stop" );
for my $line ( @script ) {
my $linemod = $line;
$linemod =~ s{DEVICENUM}{$dev_index}g;
my $str = qq{./runon $device shell su -c "$linemod"};
print "$str\n";
system( $str );
}
system( "sudo ifconfig $dev 10.100.$dev_index.1 netmask 255.255.255.0" );
system( "sudo route del -net default gw 10.100.$dev_index.2 metric 200" );
system( "sudo route add -net default gw 10.100.$dev_index.2 metric 200" );
system( "echo 0 | sudo tee /proc/sys/net/ipv4/conf/$dev/rp_filter" );
system( "echo 1 | sudo tee /proc/sys/net/ipv4/conf/$dev/accept_local" );
system( "ping -n -c10 10.100.$dev_index.2" );
system( "ping -n -c10 -I$dev 18.181.5.52" );
}
# A: 8a:71:5f:ef:c7:5e
# B: 0a:8d:31:bb:7c:96
# C: 6a:f6:8e:83:a7:7e
Something went wrong with that request. Please try again.