![]() |
Yay!
After all that hard work, it finally does what it is supposed to do. The final code was altered to:-
--- #!/usr/bin/perl use strict; sleep int(rand 60); # Change this to match your server name: my $webserver = "http://www.iainbroughton.com"; # Don't change anything below this unless you know what # you're doing. :) my $command = "ifconfig -a inet 2>/dev/null | "; $command .= "sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' "; $command .= "-e '/tunnel/d' -e '/inet/p' | wc -l"; my $network = `$command`; $command = "system_profiler -detailLevel -2 2>/dev/null | "; $command .= "grep -i \"serial number\""; my @serial_number = split ' ', `$command`; if ($network == 1) { $command = "curl -A \"Thief Killer (Mac OS X)\" "; $command .= "$webserver/$serial_number[2].html"; system $command; } --- and now produces a very pretty entry on my server log file (Obviously I've altered the IP and serial for this posting!) -- 212.159.xxx.xxx - - [03/Jul/2004:11:41:13 +0100] "GET /W902103XPJH.html HTTP/1.1" 200 0 "-" "Thief Killer (Mac OS X)" -- Thankyou so much! :) |
The only thing I don't quite understand is the
$command = "system_profiler -detailLevel -2 2>/dev/null | "; $command .= "grep -i \"serial number\"" as it doesn't show up anywhere, and the W902103XPJH.html was created manually by me. Should the serial number (as got automatically by the script) show up anyhere? At least it works though! :) |
If you want to make this less noticeable, you should avoid running the system_profiler when not connected to a network.
To do this, just add the following line right after the line that sets the $network variable. exit unless $network; |
Doesn't show up anywhere?
The script won't create the HTML file, if that's what you're thinking. And really, the HTML file doesn't need to exist in order for this to work. If it doesn't, the log will show a 404 response (instead of the 200 that you quoted) but you'll still have all of the info you need. If you're thinking that the curl command should save the HTML file somewhere, you'd be right. If the command had the proper options. What's happening as it stands is that the curl has a -A option, which sets the user agent. Then it downloads the file and sends it to standard output. If you run this script by itself you'll see the downloaded file displayed on the screen. If you wanted to save the file you'd need to add a -o or -O option to the curl command (read man curl for explanations of the options). |
No, I didn't think it would create the HTML file for me, and no, the system serial number doesn't appear at all. I don't want the file saved locally. Sorry for sounding thick, but I don't really understand what this is doing other than making a stamp (either a 200 or a 404) in my servers log, displaying the correct IP address. Is it actually supposed to show anything up in the HTML file, or just show in the server log? :confused:
|
The point is just to put a stamp in the server log. The HTML file is irrelevant.
|
In which case we have succeeded! :)
|
Quote:
|
Well yes, but I don't have the luxury of a dial up account. I'll just have to take this as a suitable measure untill I can verify it further. I'm quite content with the way that this is working at the moment, I presume the way the script is written, it doesn't matter how the machine is connected to the internet, as long as there is a connection present?
|
Quote:
|
| All times are GMT -5. The time now is 05:45 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.