Reverse tethering Android

南楼画角 提交于 2020-01-05 03:59:05

问题


I've tried to use different reverse thetering instructions for Android but no one had helped me.

I've got connection for several second (30 sec) and then connection dissappeared.

In connection manager I've seen wired unmanaged connection for my phone

I'm using Linux

How can I fix problem with dissapearing reversed internet.

Is it problem with Linux configuration?


回答1:


If you use HTC mobile, the android need an (windows) driver to active "Internet Transmission", if not driver here, you will lost connection after a few seconds.

but we can hack this without need root mobile. use this perl which connect the 6000 port of mobile. this script can enable "Internet Transmission", and you can see an icon show on panel.

    ● cat bin/htcsock.pl 
    #!/usr/bin/perl  

    use IO::Socket::INET;  
    #6000/tcp open  X11
    do{
    open IN,"/proc/net/arp"; @arp=<IN>; close IN;
    @d=grep ! /00:00:00:00:00:00/,grep /0x2.*usb0/,@arp;
    } until($d[0]);
    $_=$d[0]; s/\ .*//; chomp; print "sock:\t$_\n";

    my $sock = IO::Socket::INET->new(PeerAddr => $_ , PeerPort => 6000,                 Type=>SOCK_STREAM, Proto=>"tcp") or die "socket connect fail. $@\n";  

    print $sock "\x00\x02\x00\x00"; receivesock();
    print $sock "\x00\x03\x00\x00"; receivesock();
    print $sock "\x00\x05\x00\x00";
    close $sock;  

    sub receivesock{
    local $/=\4;
    print "Receive: --"; print unpack "H*",<$sock>; print "--\n";
    }



回答2:


As an alternate method (which does the same as the Perl script shown here, but without the need of Perl), you can use what's suggested here, which I'll transcribe below (with some modifications I made):

First, install bind9, since it'll avoid problems with DNS forwarding.

sudo apt-get install bind9

Add a POSTROUTING rule to iptables:

sudo iptables -A POSTROUTING -t nat -j MASQUERADE

Allow packet forwarding:

echo 1 | sudo tee -a /proc/sys/net/ipv4/ip_forward

Now plug in your phone and select 'internet pass through'.

Wait for the device to appear in ifconfig.

Check it is also in arp.

I found I had to unplug the device then plug it in again for it to appear in arp, things don't work properly if arp doesn't show the device.

The device will then sit waiting for HTC Sync to send it a message, so you have to mock HTC Syncs message:

#change this line to be more specific if you have more than one usb network device
phone_usb_device="usb"
get_ip ()
{
    arp -n | grep $phone_usb_device | awk '{print $1}'
}

#TODO: This needs a timeout and loop needs cleaning up, but works fine and borrowed from another post.
echo "waiting for IP on computer usb"
while [[ `get_ip` < 192 ]];do sleep 2; done
phoneip=`get_ip`
echo "IP adress is $phoneip "

echo -n -e "\x00\x02\x00\x00" | nc -q 2 $phoneip 6000 > /dev/null

The latter part could be turned into a D-Bus script.

If you just want to test the Internet Pass Through feature, you can use the very last line only, for all the phone needs is that binary sequence on port 6000.

Hope that helps.




回答3:


Reverse tethering for android

Here is steps for reverse tethering click here It required root you're device.

It works for me.



来源:https://stackoverflow.com/questions/18401704/reverse-tethering-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!