蓝牙数据通讯,实现内网电脑访问外网电脑

       最近突然想到了一个可以绕开单位安全管控软件,让单位内部办公电脑连上外网的方法。大概是这个样子,让单位办公电脑与自己的外网电脑进行蓝牙配对,然后用配对成功的蓝牙进行网络数据交互。这里大家可能会想用一下蓝牙的网络共享功能,分分钟不就实现了,其实这里是有问题的,因为这样会在单位内部办公电脑上虚拟出一个网卡,马上会被单位安全管控软件识别,进而被网络管理员发现,至少我们单位是这样的,所以不能这样用,我这里用Java写了一个蓝牙数据通讯的程序,同时考虑到蓝牙数据通讯较慢,直接用浏览器访问太慢,又用Python爬了几个自己经常访问的网站,用爬虫只访问有用信息,减少蓝牙数据通讯的数据量,最后总体感觉相当不错。下面以办公电脑连接外网实现中英文翻译为例进行介绍。拓扑图如下:

蓝牙数据交换功能用Java语言实现,其中用到了[bluecove-2.1.1.jar]蓝牙功能操作包。客户端安装在内网电脑上(比如办公电脑),在接收到内网电脑访问外部网络访的Socket请求后,自动与外网电脑进行蓝牙连接,并将Socket通讯数据转为蓝牙通讯数据,镜像至外网,主要代码如下:

public class SocketServer {
	private String bluetoothRemoteUrl = null;
	
	public SocketServer() {}
	
	public void start() throws IOException {
		try (ServerSocket server = new ServerSocket(SocketConfig.SERVER_PORT,SocketConfig.SERVER_BACKLOG,
				InetAddress.getByName(SocketConfig.SERVER_ADDRESS))) {
			System.out.print("Socket通讯监听[" + SocketConfig.SERVER_ADDRESS + ":" + SocketConfig.SERVER_PORT + "]启动成功...");
			
			ExecutorService service = Executors.newFixedThreadPool(BluetoothConfig.SERVICE_POOL);
			System.out.println("服务线程池[" + BluetoothConfig.SERVICE_POOL + "]初始化成功...");
			
			Socket socket = null;
			BluetoothChannel channel = null;
			while(true) {
				try {
					socket = server.accept();
					System.out.println("客户端[" + socket.getInetAddress().getHostAddress() + "]已连接...");
				}
				catch(Exception e) {
					System.out.println("客户端连接错误[" + e.getMessage() + "]");
					
					if (socket != null) {
						socket.close();
					}
					continue;
				}
				
				System.out.print("开始与蓝牙服务[" + BluetoothConfig.REMOTE_UUID + "@" + BluetoothConfig.REMOTE_ADDRESS + "]建立连接...");
				try {
					if (StrUtil.isBlank(bluetoothRemoteUrl)) {
						bluetoothRemoteUrl = BluetoothTools.fetchRemoteUrl(BluetoothConfig.REMOTE_ADDRESS,
								new UUID(BluetoothConfig.REMOTE_UUID,true),ServiceRecord.NOAUTHENTICATE_NOENCRYPT,false);
					}
					channel = BluetoothTools.open(bluetoothRemoteUrl);
					System.out.println("已连接");
				}
				catch (Exception e) {
					System.out.println("连接错误[" + e.getMessage() + "]");
					
					if (socket != null) {
						socket.close();
					}
					if (channel != null) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值