代码改变世界

LINUX 和WINDOWS下的自动登录小脚本

2016-04-20 15:49  梁小白  阅读(1820)  评论(0编辑  收藏  举报

每天上班第一件事,就是连接公司LAB里面的机器,但首先要过一个防火墙,每次输用户名密码是很累人的事,

以下是两个脚本,可以放在启动项中,开机便自动登录

 

WINDOWS:

@echo off  
ipconfig /flushdns 
echo set sh=WScript.CreateObject("WScript.Shell") > telnet_tmp.vbs
echo WScript.Sleep 200 >> telnet_tmp.vbs 

echo sh.SendKeys "username{ENTER}" >>telnet_tmp.vbs 
echo WScript.Sleep 200 >>telnet_tmp.vbs  
echo sh.SendKeys "password{ENTER}">>telnet_tmp.vbs  

start telnet 9.XXX.XXX.92  //your ip address
cscript //Nologo telnet_tmp.vbs

  

 

LINUX OR OS X

#!/usr/bin/expect
set timeout 20
#set hostName [lindex $argv 0]
#set userName [lindex $argv 1]
#set password [lindex $argv 2]
set hostName "9.xxx.xxx.247"
set userName "username"
set password "passw0rd"

spawn telnet $hostName

expect "'^]'."
exit
expect "FSO"
expect "Username:"
send "$userName\r"
expect "Password:"
send "$password\r";
interact