如何在Android中以编程方式使用本地vpn跟踪用户浏览器的网址?

时间:2018-10-23 11:27:23

标签: android session tcp vpn android-vpn-service

如何通过在Android中以编程方式使用本地vpn跟踪用户浏览器的网址?我正在使用ToyShark本地VPN代码。通过使用此库,我可以使用套接字数据工作器捕获用户浏览器的操作。

private void writeTCP(Session session) {
    SocketChannel channel = (SocketChannel) session.getChannel();
    String name = PacketUtil.intToIPAddress(session.getDestIp()) + ":" + session.getDestPort() +
            "-" + PacketUtil.intToIPAddress(session.getSourceIp()) + ":" + session.getSourcePort();
    byte[] data = session.getSendingData();

    String s = new String(data);
    System.out.println(TAG+"writeTCP-----> " + s);

    ByteBuffer buffer = ByteBuffer.allocate(data.length);
    buffer.put(data);
    buffer.flip();

    try {
        channel.write(buffer);
        //Log.d(TAG,"finished writing data to: "+name);
    } catch (NotYetConnectedException ex) {
        Log.e(TAG, "failed to write to unconnected socket: " + ex.getMessage());
    } catch (IOException e) {
        Log.e(TAG, "Error writing to server: " + e.getMessage());

        //close connection with vpn client
        byte[] rstData = TCPPacketFactory.createRstData(
                session.getLastIpHeader(), session.getLastTcpHeader(), 0);
        try {
            writer.write(rstData);
            SocketData socketData = SocketData.getInstance();
            socketData.addData(rstData);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //remove session
        Log.e(TAG, "failed to write to remote socket, aborting connection");
        session.setAbortingConnection(true);
    }
}

上面写的TCP方法有一行

byte[] data = session.getSendingData();
String url = new String(data); 
System.out.println(TAG+"writeTCP-----> " + url);

通过使用上面的writeTCP日志,我可以跟踪用户的url,但是url结果将类似于

��������������������������www.videocond2h.com��������#����Ǹޮ̷�;�[+敊+�>M�N)Hi���o� S�j�.i��x������g�ν    �ShڄVO쨿k��4X�Oӷ>�-�kt:����|+�K�ƣ&�-b���*״%�o�=Y�O�Λ���.��ĊU���6~�ݓ����6f�xt=*Q�UQ��O}������������������������������h2http/1.1uP������������3��+��)::�������� ��k0b�E�x�Z������-�Q�o!�OT���v��-����+��

我如何从下面的代码行中获取正确的完整URL。网址为 www.videocond2h.com

 byte[] data = session.getSendingData();

1 个答案:

答案 0 :(得分:0)

如果您已经拥有本地VPN,则可以从tcp / udp ByteBuffer

获取信息
        ByteBuffer packet_buffer = packet.backingBuffer;
        packet_buffer.mark();
        byte[] tmp_bytes = new byte[packet_buffer.remaining()];
        packet_buffer.get(tmp_bytes);
        packet_buffer.reset();
        Message message = new Message(tmp_bytes);
        Name query_domain = message.getQuestion().getName();
        String query_string = query_domain.toString();