Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 63 lines (55 sloc) 2.79 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[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" );
for my $device ( qw[A B] ) {
my ( $num ) = $device =~ tr{ABC}{123}r;
my $dev = $devs[ $num ];
my $linemod = "setprop sys.usb.config rndis,adb";
$linemod =~ s{DEVICENUM}{$num}g;
my $str = qq{./runon $device shell su -c "$linemod"};
print "$str\n";
system( $str );
print "Sleeping 3 seconds for rndis change to take effect and adb to reboot \n";
system("sleep 3");
print ("Stop network manager to prevent autoconf \n");
system( "sudo service network-manager stop" );
for my $line ( @script ) {
my $linemod = $line;
$linemod =~ s{DEVICENUM}{$num}g;
my $str = qq{./runon $device shell su -c "$linemod"};
print "$str\n";
system( $str );
}
system( "sudo ifconfig $dev 10.100.$num.1 netmask 255.255.255.0" );
system( "sudo route del -net default gw 10.100.$num.2 metric 2" );
system( "sudo route add -net default gw 10.100.$num.2 metric 2" );
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 -c3 10.100.$num.2" );
system( "ping -c3 -I$dev 8.8.8.8" );
}
# A: 8a:71:5f:ef:c7:5e
# B: 0a:8d:31:bb:7c:96
# C: 6a:f6:8e:83:a7:7e
Jump to Line
Something went wrong with that request. Please try again.