P=NP
May 25th, 2009, 05:24 PM
Some background,
I'm just learning to program and wrote a small script:
#!/bin/bash
echo 'Change your MAC automatically!'
sleep .7
echo "Shutting down eth0"
sudo ifconfig eth0 down
sleep 2
sudo macchanger -A eth0
echo 'Bringing eth0 back up'
sudo ifconfig eth0 up
sleep 5
echo 'Bye!'
sleep 1.5
If that looks very rudimentary, it is because it is. This is my first ever workable program that I wrote myself without having to look at examples from the internet. Obviously I have a long way to go. However I think I just had a programming epiphany! So this got me looking around the net for Bash scripting information. I came across an article that said if you can learn to string together a few commands in a Bash script, you can learn to program Python. How convenient - I wanted to learn Python anyway! And this got me thinking...
I know the above takes a lot of things for granted. Like the device is "eth0" or that the package macchanger is installed. I think I would have needed to learn how to use grep and awk. I didn't really look too deep into it before the direction change. Anyway, I think I'm starting to get how it works. I have a local network with two clients that I have to telnet into on a regular basis, kill a process, delete two file, ftp replacements, restart the process, then end the session or reboot the client. I would like to automate this process. For now I would like to have this program run for only me so no user input is necessary for the IP's of the clients or the location of the files. In the future I would like to add that capability and also the capability to write to a file the names and permissions, time taken, etc... I shouldn't get ahead of myself.
My questions are:
1. What modules are required (I'm assuming a module is a reusable piece of code that provides some function - like opening a telnet session/protocol)
2. Could someone provide a basic outline for me? Not actual code, but something like:
shebang/and/stuff yeah
import somejunk
import somecoolstuff
#set variables
How to do stuff,etc
Not actual code. Oh, and how would I go about finding out the syntax for each module?
Here's an example of some code, but it does some weird stuff and outputs two files that I can't open with anything, so needless to say it didn't teach me much.
import getpass
import sys
import telnetlib
HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
3. Is this too advanced for me? Please correct me or steer me in the right direction.
Thanks!
I'm just learning to program and wrote a small script:
#!/bin/bash
echo 'Change your MAC automatically!'
sleep .7
echo "Shutting down eth0"
sudo ifconfig eth0 down
sleep 2
sudo macchanger -A eth0
echo 'Bringing eth0 back up'
sudo ifconfig eth0 up
sleep 5
echo 'Bye!'
sleep 1.5
If that looks very rudimentary, it is because it is. This is my first ever workable program that I wrote myself without having to look at examples from the internet. Obviously I have a long way to go. However I think I just had a programming epiphany! So this got me looking around the net for Bash scripting information. I came across an article that said if you can learn to string together a few commands in a Bash script, you can learn to program Python. How convenient - I wanted to learn Python anyway! And this got me thinking...
I know the above takes a lot of things for granted. Like the device is "eth0" or that the package macchanger is installed. I think I would have needed to learn how to use grep and awk. I didn't really look too deep into it before the direction change. Anyway, I think I'm starting to get how it works. I have a local network with two clients that I have to telnet into on a regular basis, kill a process, delete two file, ftp replacements, restart the process, then end the session or reboot the client. I would like to automate this process. For now I would like to have this program run for only me so no user input is necessary for the IP's of the clients or the location of the files. In the future I would like to add that capability and also the capability to write to a file the names and permissions, time taken, etc... I shouldn't get ahead of myself.
My questions are:
1. What modules are required (I'm assuming a module is a reusable piece of code that provides some function - like opening a telnet session/protocol)
2. Could someone provide a basic outline for me? Not actual code, but something like:
shebang/and/stuff yeah
import somejunk
import somecoolstuff
#set variables
How to do stuff,etc
Not actual code. Oh, and how would I go about finding out the syntax for each module?
Here's an example of some code, but it does some weird stuff and outputs two files that I can't open with anything, so needless to say it didn't teach me much.
import getpass
import sys
import telnetlib
HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()
3. Is this too advanced for me? Please correct me or steer me in the right direction.
Thanks!