Linux Ubuntu如何远程协助Windows

版权声明:本文为作者原创,未经允许,请勿转载。 https://blog.csdn.net/qq_42876636/article/details/82954582

一、安装rdesktop

  1. 打开Linux Ubuntu
  2. Ctrl - Alt - T打开终端
  3. 使用万能的安装指令$ sudo apt-get install rdesktop安装rdesktop
  4. 使用指令$ rdesktop --help测试rdesktop是否成功安装

二、设置Windows

  1. 打开Windows
  2. 右键"我的电脑" (好像Win7是"此电脑),选"属性"
    此电脑
  3. 点击"远程设置"
    远程设置
  4. 把有关的都勾成允许
    属性设置
  5. Win - R打开"运行"
  6. 输入cmd打开Windows命令行
  7. 在命令行中输入ipconfig查看你的IP地址
    找到"以太网适配器 以太网:"那一段
    找到"IPv4 地址"那一行
    把后面那一串数字记下来,那是WindowsIP地址

三、使用rdesktop

  1. $ rdesktop IP_address远程协助IP_address,默认不全屏 (协助后屏幕大小不可更改),无声音
  2. $ rdesktop -f IP_address全屏显示
  3. $rdesktop -r attr IP_adress设置属性,例:
  • $ rdesktop -f -r sound:on IP_address开启声音
  • $ rdesktop -f -r sound:local IP_address把声音带到本地播放器 (须与-r sound:local联用,不然没声音)
  1. $ rdesktop -u username IP_address使用username作为登录用户名
  2. $ rdesktop -p password IP_address使用password作为登录密码 (如果此项不选且Windows设置了密码,那么会显示出开机登录界面,必须使用强密码,不能用PIN码)

四、编写Linux Bash脚本

  1. 由于rdesktop每个参数都很长,一般都会用到如下指令
    $ rdesktop -f -u username -p password -r sound:on -r sound:local IP_address
    十分繁琐,所以可以将rdesktop的调用写在Bash脚本中
  2. 脚本内容
#control(一般在第一行写文件名,可以不用)
#!/bin/bash		#指明用/bin/bash作为解释器,不可省略

#设置默认属性
username="default_uesrname"		#设置默认username,default_username根据你的需求自行设置
password="default_password"		#设置默认password,default_password根据你的需求自行设置
declare -i full_screen=1		#设置默认的屏幕大小,0代表不全屏,其他代表全屏,根据你的需求自行设置
declare -i sound_on=1			#设置默认声音是否开启,0代表不开启,其他代表开启,根据你的需求自行设置
declare -i sound_local=1		#设置默认声音是否带到本地,0代表否,其他代表是,根据你的需求自行设置
ip="default_ip"				#设置默认的IP地址,default_ip根据你的需求自行设置

#显示default信息
function default
{
	echo "username\t: $username"
	echo "password\t: $password"
	echo "full screen\t: $full_screen"
	echo "sound\t: $sound_on"
	echo "sound to local\t: $sound_local"
	echo "ip:\t $ip"
}

#显示help信息的函数
function help
{
	echo "control [options] [IP_address]"
	echo
	echo "options:"
	echo "\t-d\tshow the default options"
	echo "\t-f\t(not) show full-screen"
	echo "\t--help\tshow this help document"
	echo "\t-l\t(not) bring the sound to local"
	echo "\t-p <password>\tuse <password> as password"
	echo "\t-s\t(not) turn on the sound"
	echo "\t-u <username>\tuse <username> as username"
}

echo	#输出空行

declare -i mode=0	#0代表无,1代表username,2代表password
declare -i count=0
for arg in "$@"
do
	count = $count + 1
	case $arg in
	"-d")default	#输出默认属性
	"-f")full_screen=$full_screen - 1	#0变成-1,1变成0
	"--help")help	#输出帮助信息
	"-l")sound_local=$sound_local - 1
	"-p")mode=2
	*)
		case $mode in
		0)ip=$arg
		1)username=$arg
		2)password=$arg
		esac
	;;
	esac
done

#生成指令
instruction="rdesktop"
instruction="$instruction -u \"$username\""		#设置用户名
instruction="$instruction -p \"$password\""		#设置密码
if $full_screen;; then
	instruction="$instruction -f"	#设置全屏模式
fi
if $sound_on;; then
	instruction="$instruction -r sound:on"	#设置声音开启
fi
if $sound_local;; then
	instruction="$instruction -r sound:local"	#设置把声音带到本地
fi
instruction="$instruction $ip"	#设置IP地址

#执行指令
$instruction
exit $?		#使用rdesktop的返回值作为返回值

注:由于最近我的Linux崩溃了,本段代码无法测试,可能会有小错误,请见谅!

猜你喜欢

转载自blog.csdn.net/qq_42876636/article/details/82954582