Monday, October 03, 2011

Office Communicator 2007 - send message

It would have been nice if there was a command line way of sending message from office communicator. Googled and did not found anything. Finally created a fragile scritp using WSHShell . It is fragile but it works and saves time for me.

option explicit

' Global variable to hold the initials and name mapping.
' Commandline may have initials in place of the name.
dim Names
Set Names = CreateObject("Scripting.Dictionary")
Names.Add "C1", "Contact1"
Names.Add "C2", "Contact2"
Names.Add "C3", "Contact3"

' Global variable used by mySendKeys function.
dim Wsh
set Wsh = Wscript.CreateObject("Wscript.Shell")

if (Wscript.Arguments.Count < 1) Then
Wscript.Echo "Usage: m "
Wscript.Quit(1)
End if

dim name
name = UCASE(Wscript.Arguments(0))
if (Names.Exists(name)) then
name = Names.item(name)
end if

'Wscript.echo name

Wsh.Run "communicator" ' Run communicator
Wscript.Sleep 500 ' Give time for communicator to open.
mySendKeys "{TAB}" ' TAB
mySendKeys "{DOWN}" ' Down Arrow
mySendKeys name ' Search for the contact in my list.
Wscript.Sleep 500 ' Wait for select to happen.
mySendKeys "{ENTER}" ' Enter
Wscript.Quit(0) ' Success

Function mySendKeys(key)
wsh.AppActivate "Office Communicator"
wsh.SendKeys key
End Function

Friday, September 30, 2011

How to get rid of REMOTE HOST IDENTIFICATION HAS CHANGED message

Ever irritated by the message (see below) due to the remote host public key change (remote host was re-installed).

If you are not worried about the security try these in your ~/.ssh/config .
NOTE: This is not secure so make your call. I am working on intranet and do not worry about man in the middle attack.

Host *
# Ignore Host ID changes.
StrictHostKeyChecking no
# Do not store the known hosts.
UserKnownHostsFile /dev/null
# -X option by default.
ForwardX11 yes



Irritating message:
~$ ssh -o "StrictHostKeyChecking no" username@host.domain
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
82:e7:bc:0c:6d:cc:3c:e2:c7:de:ee:2a:b2:af:31:f9.
Please contact your system administrator.
Add correct host key in /home/myacct/.ssh/known_hosts to get rid of this message.
Offending key in /home/myacct/.ssh/known_hosts:5
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Permission denied (publickey,gssapi-with-mic,password).

Tuesday, September 27, 2011

inetwiz automation

inetwiz is a tool which I have been using in Windows XP to update the IE proxy setting.
The manual process has been a pain and I wanted to automate it badly.
Experimented with multiple tools - Registry updates, Python. A friend suggested to use VBS.
The VBS did the trick and I was able to use Wscript Run, AppActivate and sendKeys method to automate the proxy update and opening the URL in internet explorer.

Here is the script

option explicit

' Global variable used by mySendKeys function.

dim Wsh

set Wsh = Wscript.CreateObject("Wscript.Shell")

if (Wscript.Arguments.Count < 2) Then

Wscript.Echo "Usage: i /auto|/man URL"

Wscript.Quit(1)

End if

'WScript.Echo (Wsh.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable"))

if (Wscript.Arguments(0) = "/man") Then

' VB Script does not support double equal.

' If Proxy is not enabled, enable it.

if (Wsh.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable") = 0) Then

enableManProxy()

End if

Wsh.Run "iexplore " & Wscript.Arguments(1)

Elseif (Wscript.Arguments(0) = "/auto") Then

' If Auto Proxy is not enabled.

' VB Script does not support double equal.

if (Wsh.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable") = 1) Then

enableAutoProxy()

End if

Wsh.Run "iexplore " & Wscript.Arguments(1)

Else

Wscript.Echo "Usage: i /auto|/man URL"

End if

Function enableAutoProxy()

' Enable Automatic Proxy

Wsh.Run "inetwiz"

Wscript.Sleep 1000 ' Give time for application window to open.

mySendKeys "%n" ' Alt + n

mySendKeys " " ' Space

mySendKeys "{Tab}" ' Tab

mySendKeys " " ' Space

mySendKeys "{Tab}" ' Tab

mySendKeys "{Tab}" ' Tab

mySendKeys " " ' Space

mySendKeys "%n" ' Alt + n

mySendKeys "%o" ' Alt + 0

mySendKeys "%n" ' Alt + n

mySendKeys " " ' Space/Finish button

End Function

Function enableManProxy()

Wsh.Run "inetwiz"

Wscript.Sleep 1000 ' Give time for application window to open.

mySendKeys "%n" ' Alt + n

mySendKeys " " ' Space

mySendKeys "{Tab}" ' Tab

mySendKeys " " ' Space

mySendKeys "{Tab}" ' Tab

mySendKeys " " ' Space

mySendKeys "%n" ' Alt + n

mySendKeys "%n" ' Alt + n

mySendKeys "%n" ' Alt + n

mySendKeys "%o" ' Alt + 0

mySendKeys "%n" ' Alt + n

mySendKeys " " ' Space/Finish button

End Function

Function mySendKeys(key)

wsh.AppActivate "Internet Connection Wizard"

wsh.SendKeys key

End Function

Sunday, September 11, 2011

Nested screen sessions

I have been using GNU screens since few years but never thought of using nested screen SESSIONS. Nested screen sessions comes handy when you want to SSH to other server from screen WINDOWS. Here is my recipe for handling nested screen sessions.

* ssh jayrajput@serverA
* screen -e ^Ee # Change escape character from Ctrl-A to Ctrl-E. see escape function in man screen.
* screen -d -m -S serverA # Create a new detached screen session named "serverA" on serverA in detached mode.
* screen -x serverA # Attach to the "serverA" screen session.
* Ctrl-E + c # create a new screen window
* ssh jayrajput@serverB # ssh to serverB
* screen # Run screen on serverB


Use Ctrl-A as command leader in inner screen sessions .
User Ctrl-E as command leader in outer screen sessions.

Setting the hardstatus your .screenrc also comes handy

hardstatus alwayslastline
hardstatus string "%t"

This will show the hostname in the outer screen session status. Do not know why but it does show the hostname.

Tuesday, January 04, 2011

Continuous Ping

ping -t


This is helpful when you do not want to open cmd window and execute ping command from the run prompt.