×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to pull output from CMD window?

How to pull output from CMD window?

How to pull output from CMD window?

(OP)
I am trying to write a script that will detect if an iPhone is connected to the routers WiFi. Initially I worked on the premise that all I needed to do was Ping the iPhone's fixed IP address of 192.168.1.12. Unfortunately after spending a few hours building and testing a script I discovered that the iPhone goes into sleep mode timeout if not used thus switching WiFi and Bluetooth to standby to conserve battery power.. so pinging the iPhone's IP address fails.

After that I discovered that the Vigor2860Ln router does in fact maintain the IP address of the iPhone even when sleeping so I came up with the following VBScript which works fine - I can login to the router and produce the required output in a CMD window but I cannot find how to pull the returned output to see if the IP address 192.168.1.12 exists

Any help would be appreciated.


'(Start of Script)--------------------------

Set MyObject = CreateObject("WScript.Shell")

MyObject.run "cmd"
WScript.Sleep 500

MyObject.SendKeys"telnet 192.168.1.1"
MyObject.SendKeys("{Enter}")
WScript.Sleep 500

MyObject.SendKeys"admin" '(UserName)
MyObject.SendKeys("{Enter}")
WScript.Sleep 500

MyObject.SendKeys"******" '(User Password)
MyObject.SendKeys("{Enter}")
WScript.Sleep 500

MyObject.SendKeys "wl stalist show " '(Query Router Data)
MyObject.SendKeys "quit{ENTER}"

'(End of Script)--------------------------


(The above script Produces a CMD window containing the following.)

Index Status IP Address MAC Address Associated with
1 A 192.168.1.16 MAC Address 1 SSID #1
2 A 192.168.1.15 MAC Address 2 SSID #1
3 A 192.168.1.13 MAC Address 3 SSID #1
4 A 192.168.1.12 MAC Address 4 SSID #1 (Does this IP or MAC address exist? - If not then iPhone is NOT connected)

RE: How to pull output from CMD window?

If you look at my example vbscript in thread329-1798189: string in rtf you will see one method of getting the output from a CMD window.

RE: How to pull output from CMD window?

(OP)
Many thanks for your suggestion strongm. However looking at your thread it seems to deal a lot more with RTF which I know nothing about and cannot see how I would implement that in my script. However since my original post I have managed to research further information and have now answered my own question as can be seen from my finished code below, and works as I need it to. The only drawback I have found is that if the focus moves away from the CMD window when the script is running it causes the script to crash and burn. This could happen if the user is working on the PC, or even if another program takes the focus. So now that I have proved the functionality of the script I am now looking to re-write what I have in VB6 or VB.NET or maybe PowerShell using sockets which should do away with a CMD window and which should also negate focus loss smile

I hope my code helps others who are trying to get their iPhones to be seen on their networks (When phone is in range) and which could then be used to control other devices such as opening/closing ports for security or even activate/de-activate an alarm system. Android phones apparantly have an option to keep alive their WiFi/Bluetooth wheras IOS does not.



'(Start of Script)--------------------------

Const ForReading = 1

Do

WScript.Sleep 15*60*1000

set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.run("telnet.exe 192.168.1.1")
WshShell.run"telnet.exe -f telnet.log 192.168.1.1"
WScript.Sleep 100

WshShell.SendKeys"UserName"
WshShell.SendKeys("{Enter}")
WScript.Sleep 100

WshShell.SendKeys"PassWord"
WshShell.SendKeys("{Enter}")
WScript.Sleep 100

WshShell.SendKeys "wl stalist show "
WshShell.SendKeys("{Enter}")
WScript.Sleep 100

WshShell.SendKeys "quit{ENTER}"

WScript.Sleep 1000
WshShell.SendKeys " exit"
WshShell.SendKeys("{Enter}")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("telnet.log", ForReading)

strText = objFile.ReadAll

if InStr(strText, "192.168.1.12") >0 then
WshShell.Run "cscript ""D:\0 - My Documents\Backup\Router Draytek\Port Control\VOFF.vbs""" '(Close Ports)
Else
WshShell.Run "cscript ""D:\0 - My Documents\Backup\Router Draytek\Port Control\VON.vbs""" '(Open Ports)
End If

objFile.Close

Loop

'(End of Script)--------------------------

RE: How to pull output from CMD window?

>seems to deal a lot more with RTF

Er … the specific problem being dealt with there was RTF, yes - but the solution involved grabbing the output (which happens to be the clean RTF in that example, but could be anything) from a command window (which is what you want to do). That being said, you'd have needed to do a significant amount of rewriting of your script for that particular method to work - which you can now safely avoid since you seem to have a working solution


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close