![]() |
Turn on and access PC script tutorial
This is a tutorial to turn on and access/control a pc from your N900 (or any other linux machine really).
It may seem complicated at first but it is a small introduction to using linux and a very powerful tool called shell scripts. Most of the things here you may already know. I have tried to explain steps and terms as clearly as I can (almost bordering on patronising but not intended to be) for new linux and N900 users. Having said that I'd like to put a disclaimer that this is not for the faint of heart. Be very careful what you do with your phone and do it at your own risk. Turn on a PC. WOL Wake on lan (WOL) is a method to turn on a machine with a "signal" known as a magic packet sent from another device on a network. Both the machine and the network need to be setup for this, this is not discussed here. I recommend you google for "WOL BIOS" "WOL portforwarding" to setup the machine and network. There are two ways to send the signal. You only need to use one or the other. 1) get the N900 to send it 2) Use the N900 to tell a router, NAS device or another PC to send it. 1) sending it from the N900 directly This is probably the easier method. For people who want to wake many machines on their lan and have a router capable of ssh and WOL (eg DD-WRT routers) I recommend method two. install the pygtkeditor app, this is what you use to write scripts. (applications menu -> more -> app manager -> download ->all) open an x terminal on the N900 (applications menu -> more -> x terminal) type the following and press enter to create a directory (folder) Code:
mkdir ./MyScriptsCode:
pygtkeditor /home/user/MyScripts/wakeonlan.pycopy paste the script below into the editor. for a guide to copy paste from the browser look at this post and use the stylus not your finger http://talk.maemo.org/showpost.php?p=443893&postcount=8 Code:
#!/usr/bin/pythonat the terminal use this command so that you can execute the script Code:
chmod a+x /home/user/MyScripts/wakeonlan.pyCode:
/home/user/MyScripts/wakeonlan.py "YOUR PC MAC ADDRESS"there is a way to make most of the directory commands here shorter if you want to use the command often, but we'll learn how to create a shortcut on the desktop further down the tutorial anyway. 2) telling a router to send the wake signal if you followed the step above (sending it from the N900 directly) you don't need to do this section (section 2), you can do both and nothing wrong will happen but there really is no need to do both. if you have network knowledge, a lot of PCs to wake from a WAN, or an always on DDWRT-router/low power PC I'd recommend this over step 1. if you use a DDWRT router first make sure you enable ssh on the router from both the services and managment tab. Now the script is a lot easier and waking more than one machine in your LAN from a WAN is easier too. like in section 1) above instead of Code:
pygtkeditor /home/user/MyScripts/wakeonlan.pyCode:
pygtkeditor /home/user/MyScripts/wakeonlan.shCopy paste the short script below and save the file. Code:
#!/bin/shCode:
wol "root" "192.168.1.1" "192.168.1.255" $1if you want to wake from a WAN (usually from outside your house) instead of "192.168.1.1" put your ISP ip or a DYNDNS address and set up port forwarding. Code:
chmod a+x /home/user/MyScripts/wakeonlan.shCode:
/home/user/MyScripts/wakeonlan.sh "YOUR PC MAC ADDRESS"3) turn on AND ACCESS a PC OK so now we can turn on a PC. This is a guide to access it. there are two ways to control a PC used here. SSH or VNC. I recommend SSH (and linux ofcourse). On the N900 install both vncviewer and OpenSSH client so you can do both (applications menu -> more -> app manager -> download ->all) if your PC is running Windows: install realvnc on it (you can set up SSH but it's difficult on windows) if your PC is running linux: you need OpenSSH Server or if you want to use VNC it is probably already installed (all you need to do is enable it). so now we will create a fairly crude script to not only wake but access the PC open editor Code:
pygtkeditor /home/user/MyScripts/accessremotepc.shCode:
#!/bin/shCode:
chmod a+x /home/user/MyScripts/remoteaccesspc.shNow this command in the x terminal will wake up (if not already awake), then access the pc with either vnc or ssh for vnc Code:
/home/user/MyScripts/accessremotepc.sh "YOUR PC MAC ADDRESS"Code:
/home/user/MyScripts/accessremotepc.sh "YOUR_PC_MAC_ADDRESS" "USERNAME_TO_LOG_IN_WITH" "HOST"Code:
/home/user/MyScripts/accessremotepc.sh 00:1A:2B:3C:4D:5F root 192.168.1.2Everything we have done so far has been using the command line to write scripts so we can do even more in the command line. we will now create a nice shortcut on the desktop or apps menu to access a certain PC with one click (and probably a password entry or two). you will need rootsh installed (this is now becoming more dangerous) also install leafpad if you dont like the vi editor Code:
sudo gainrootCode:
leafpad /usr/share/applications/hildon/MyPC.desktopCode:
[Desktop Entry]Lets just hope a WOL app becomes available in extras in the future. Thank you to everyone for making the forums what it is and I welcome any scripting suggestions from the gurus. |
Re: Turn on and access PC script tutorial
thanks for this. Having a small problem with it though. Everytime I try to run it with my MAC, i get a
IndexError: list index out or range Any idea what the problem is? Edit: I too hope a WOL app comes to the N900, specially one that will allow you to send magic packets out over the internet as well. 2d |
Re: Turn on and access PC script tutorial
you have to specify your mac adress like this : "FF:FF:FF:FF:FF:FF"
mayebe thats your problem ... also make sure you call the bash script and not the python script in the hildon shortcut. So if you use "method 1" make a second script to call the python script... |
Re: Turn on and access PC script tutorial
Quote:
if your trying to Wake over the internet using the first method only with a custom port, you should try changing this line Code:
s.sendto(msg, ('<broadcast>', 9))Code:
s.sendto(msg, ('YOUR_DEST', YOUR_PORT))I've not tried WOL over the internet with the first script but you could give it a go. |
Re: Turn on and access PC script tutorial
Code:
[Desktop Entry]is this right for wol shortcut :confused: |
Re: Turn on and access PC script tutorial
Quote:
I noticed that I wasn't consistent with the upper case S in "MyScripts" I've edited it to correct this. if you used an upper case or lower case S make sure you use the same throughout. |
Re: Turn on and access PC script tutorial
Quote:
Now i just need to get my routers all forwarding correctly. For some reason they don't seem to like UDP 9. 2d |
Re: Turn on and access PC script tutorial
is there any chance that i can make a shortcut to a list of wol clients?
press wol shortcut will bring you to a list, than you can chosse which wol client ( script) will be activated |
Re: Turn on and access PC script tutorial
Quote:
There is another way which is safer and that is with another script and a type of config file. create a file called pclist.cfg in the MyScripts directory Code:
pygtkeditor ./MyScripts/pclist.cfgCode:
[HomePC]now create the following script named pclistwol.sh Code:
pygtkeditor ./MyScripts/pclistwol.shCode:
#!/bin/shmake sure you do chmod a+x ./MyScripts/pclist.cfg chmod a+x ./MyScripts/pclistwol.sh so now ./MyScripts/pclistwol.sh OfficePC will wake the office PC, or ./MyScripts/pclistwol.sh will list the pcs and ask which I want to wake. you can create a shortcut for the above. |
Re: Turn on and access PC script tutorial
Has anyone else attempted to use this script over the internet for WoL?
Trying to see if the script broadcasts the packet correctly over the nets. 2d |
| All times are GMT. The time now is 13:53. |
vBulletin® Version 3.8.8