Jump to content

Telnet into pc to shut it down


Recommended Posts

Could you not write an autoit program to run at startup on the machine to be shut down and simply shut down at a scheduled time?

Does the time the PC have to shut down change each night?

If it's the autoit icon in the corner that bothers you, you can hide it...

Opt("TrayIconHide", 1)          ;0=show, 1=hide tray icon

;insert code here using Date.au3 to monitor the time, then...

Shutdown(15)  ;Force a shutdown and power down

I could, but the idea is to have an ini that the user can input the desired time into to turn the remote machines off when they want on a nightly basis. Plus, this is also educational for me because I am going to need to learn how to use telnet within autoit to control some other peripheral devices. I have gotten pretty savy with autoit, and my last battle before I can continue is this whole telnet within auto it idea. :-) Edited by Jkeith247
Link to comment
Share on other sites

  • Developers

I just had a look at this out of interest. Telnet is using all kinds of handshaking in its protocol so you need to "answer" that.

What I did was load the Telnet server on my Win7 Home and looked with a packetsniffer to see the conversion.

This script should be close to accomplish what you want.

Jos :)

; Example script to send command to Windows7 Telnet server
TCPStartup()
$Socket = TCPConnect(@IPAddress1, 23)
If $Socket = -1 Then
    ; unable to connect
    Exit
EndIf
;
; Get handshake info
GetData($Socket)  
; send handshake back
TCPSend($Socket, Binary("0xFFFA250000FFF0"))  
; Get Welcome Message
GetData($Socket)  
; Send final handshake info
TCPSend($Socket, Binary("0xFFFA2700FFF0FFFA270003534655544C4E54564552013203534655544C4E544D4F444501436F6E736F6C65FFF0"))   
; Get Login message
GetData($Socket) 
; Send Userid
TCPSend($Socket, "userid" & @CR)
GetData($Socket)
; Send Password
TCPSend($Socket, "password" & @CR)
GetData($Socket)
; Send handshake info
TCPSend($Socket, Binary("0xFFFC18"))   
GetData($Socket)
; Send command
TCPSend($Socket, "help" & @CR)
GetData($Socket)
;
TCPCloseSocket($Socket)
TCPShutdown ( )

Func GetData($Socket)
    Sleep(500)
    $recv = TCPRecv($Socket, 2048)
    If @error Then Return
    If $recv <> "" then
        ConsoleWrite('Received from TelnetServer:' & $recv & @crlf)
    EndIf
    Return $recv
Endfunc
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I just had a look at this out of interest. Telnet is using all kinds of handshaking in its protocol so you need to "answer" that.

What I did was load the Telnet server on my Win7 Home and looked with a packetsniffer to see the conversion.

This script should be close to accomplish what you want.

Jos :)

; Example script to send command to Windows7 Telnet server
TCPStartup()
$Socket = TCPConnect(@IPAddress1, 23)
If $Socket = -1 Then
    ; unable to connect
    Exit
EndIf
;
; Get handshake info
GetData($Socket)  
; send handshake back
TCPSend($Socket, Binary("0xFFFA250000FFF0"))  
; Get Welcome Message
GetData($Socket)  
; Send final handshake info
TCPSend($Socket, Binary("0xFFFA2700FFF0FFFA270003534655544C4E54564552013203534655544C4E544D4F444501436F6E736F6C65FFF0"))   
; Get Login message
GetData($Socket) 
; Send Userid
TCPSend($Socket, "userid" & @CR)
GetData($Socket)
; Send Password
TCPSend($Socket, "password" & @CR)
GetData($Socket)
; Send handshake info
TCPSend($Socket, Binary("0xFFFC18"))   
GetData($Socket)
; Send command
TCPSend($Socket, "help" & @CR)
GetData($Socket)
;
TCPCloseSocket($Socket)
TCPShutdown ( )

Func GetData($Socket)
    Sleep(500)
    $recv = TCPRecv($Socket, 2048)
    If @error Then Return
    If $recv <> "" then
        ConsoleWrite('Received from TelnetServer:' & $recv & @crlf)
    EndIf
    Return $recv
Endfunc

Zohmygod it worked!!!! Thank you so much!

How did you come about this? What are the binary strings you are sending?

Thanks again!

Link to comment
Share on other sites

  • Developers

How did you come about this? What are the binary strings you are sending?

Thanks again!

Just Google for "telnet protocol commands" and you will find a welt of information... an example

As mentioned, I did a capture with a packetsniffer of a regular telnet session to a Win7 Telnet server and used that as the base to translate it to the posted script.

Jos :)

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Just Google for "telnet protocol commands" and you will find a welt of information... an example

As mentioned, I did a capture with a packetsniffer of a regular telnet session to a Win7 Telnet server and used that as the base to translate it to the posted script.

Jos :)

Well hey man, thanks again, this is huge.

Link to comment
Share on other sites

Hi.

1.) connect and auth to the inter process communication (IPC$):

net use \\192.168.1.17\ipc$ /user:SomeLocalAdminUserOfThatPC cleartextpassword
or
... /User:DomainName\SomeDomainUserWithLocalAdminRights ...

2.) restart the Win box:

shutdown -r -t 0 -f -m \\192.168.1.17

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

  • 1 month later...

A couple of other ways...

1. Use WMI and reboot/shutdown the computer remotely (assuming you have admin rights on each box) - script can run as scheduled task a remote machine or local.

2. Use PSShutdown - can handle lists of machines and so on.

HTH!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...