OK so I have this script here that works perfectly for me, as far I know. I am just wondering if there are any improvements that can be made such as subroutines and etc.
Here is the script and I am looking forward to your critiques.
–the administrator password
set the_pass to “*********”
–the whole date including time
set the_date to (current date) as text
–path to nmap log
set file_open to “STURM:Users:iconan:nmaplog.txt”
–set some search information
set search_text to the_date
–path to nmap log as alias
set the_file to “STURM:Users:iconan:nmaplog.txt” as alias
–another use for the current date but not as text
set the_2date to current date
–the whole date not including time
copy word 2 of ((current date) as text) & " " & word 3 of ((current date) as text) ¬
& " " & word 4 of ((current date) as text) to the_Filedate
–get the creation date of nmap log
copy (info for the_file) to fileInfoRecord
tell fileInfoRecord
set the_Credate to the creation date
end tell
–get the difference between execution date and creation date of nmap log
set the_diff to the_2date - the_Credate
–if the log is older than one week rename it including date of execution of script
if the_diff is greater than 604800 then
tell application “Finder”
set the_name to name of the_file
set name of the_file to the_name & the_Filedate
end tell
end if
–do shell scripts to gather information on computers and router in network
set _nmap to do shell script ¬
“sudo /sw/bin/nmap -sT -v -O 192.168.1.100” password the_pass with administrator privileges
set _nmap2 to do shell script ¬
“sudo /sw/bin/nmap -sT -v -O 192.168.1.101” password the_pass with administrator privileges
set _nmap4 to do shell script ¬
“sudo /sw/bin/nmap -sT -v -O 192.168.1.102” password the_pass with administrator privileges
set _nmap5 to do shell script ¬
“sudo /sw/bin/nmap -sT -v -O 192.168.1.103” password the_pass with administrator privileges
set _nmap3 to do shell script ¬
“sudo /sw/bin/nmap -sT -v -O 192.168.1.1” password the_pass with administrator privileges
–prepare the days log file
set _nmaplog to return & return & the_date & return & return & _nmap & return & return ¬
& _nmap2 & return & return & _nmap3 & return & return & _nmap4 & return & return ¬
& _nmap5 & return & return
–write the log and create log file if it does not exist
set the_log to open for access file (((path to current user folder) as string) & “nmaplog.txt”) with write permission
try
write _nmaplog to the_log starting at eof
close access the_log
on error
try
close access the_log
end try
end try
–open log and look for date of script execution and change color and size
tell application “Tex-Edit Plus”
activate
open {file_open} as alias
select contents of window 1
search selection looking for search_text
set size of contents of selection to 18
set color of contents of selection to blue
end tell
–open log and look for IP addresses on local network beginnning with “192” and change size and color
tell window 1 of application “Tex-Edit Plus”
select insertion point before paragraph 1 of window 1
repeat
search looking for “192” with searching from cursor
if result is not false then
set first_word to get word offset of selection
set last_word to ((get word offset of selection) + 3)
select words first_word thru last_word of window 1
set size of contents of selection to 16
set color of selection to red
else
exit repeat
end if
end repeat
end tell
–quit Tex-Edit" application
tell application “Tex-Edit Plus”
quit saving yes
end tell
Thanks…