-1

如何以编程方式在 android 中使用本地 vpn 跟踪用户浏览器 url?我正在使用 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��-����+��

我怎样才能从下面的代码行中获得正确的完整网址。网址是www.videocond2h.com

 byte[] data = session.getSendingData();

4

1 回答 1

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();
于 2018-10-23T11:41:44.420 回答