Top
JohnKlann / scripting (Page 2)

Python: How to get external IP address

Here is a short simple way to get the external ip address of a machine using python. This of course is useful if your machine is sitting behind a router or a sub network. So unfortunately there is no one liner in python to grab your external ip address which means a third party service must be used. However you can be your own “third party” service if you own a website. (If you don’t you can always use mine!)

Step 1:

Create a php file called getmyip.php you will want to include the following code:

<?php

$ipaddress = $_SERVER["REMOTE_ADDR"];

Echo "Your IP is $ipaddress!";

?>

Upload this to your website and mark the location.

Step 2:

Create a python file called my_external_ip.py you will want to include the following code:

import urllib

import re

def get_external_ip():
site = urllib.urlopen("http://yourwebsite.com/getmyip.php").read() #if you want to use my website the url is: http://johnklann.com/getmyip.php
ip=re.findall(r'[0-9]+(?:\.[0-9]+){3}', site)
address = ip[0]
print address
return address

get_external_ip()

Then just execute the python script.

You can find the source here

jklann

How To: Change a registry key with VBS + User Input Screensaver Timeout Duration

So have you ever been working on a work computer and the screen saver timeout period is 15 minutes? Then you go to change it and the properties box is grayed out? Well there is good news you can change this through windows registries. The following vbs script does just that for Windows XP, Windows Vista, and Windows 7.

Now windows uses time in seconds. So 3600 seconds equals 1 hour. This script uses an input box to allow the time to be adjusted based on your preference.

All you have to do is copy and paste the code into notepad and save as screensaver.vbs That’s it double click the file, it will prompt you for a duration click ok and now your screensaver timeout duration has now been adjusted. You can look at the screensaver properties and you will see the change. Another option is to view it in regedit if you feel so inclined.

A video demonstration will be provided shortly.

'System variables
Dim objShell, RegLocate, RegLocate1
Set objShell = WScript.CreateObject("WScript.Shell")
'Creating the input box
strUserInput = InputBox( "Please enter Screen saver duration time out (3600 = 1 Hr) Default value is 900:" )

'Fucntion to check for vailid entries
Function InputCheck(strUserInput)
'checks to make sure that the input field is not blank
if strUserInput =0 then
'warning message box
MsgBox "Please enter a duration"
strUserInput = InputBox( "Please enter Screen saver duration time out (3600 = 1 Hr) Default value is 900:" )
End If
'checks to make sure that a negative number was not inserted
if strUserInput  'warning message box
MsgBox "Please enter a valid duration minimun value of 900s = 15 mintues"
strUserInput = InputBox( "Please enter Screen saver duration time out (3600 = 1 Hr) Default value is 900:" )
End If
'checks to make sure that the input is more than 900 seconds
if strUserInput  'warning message box
MsgBox "Please enter a valid duration minimun value of 900s = 15 mintues"
strUserInput = InputBox( "Please enter Screen saver duration time out (3600 = 1 Hr) Default value is 900:" )
End If
'if it passes all other input checks this actually submits the change and updates the registry
if strUserInput >899 then
On Error Resume Next
'selects the registry key to change
RegLocate = "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop\ScreenSaveTimeOut"
'writes the registry Value and key with the registry value type
objShell.RegWrite RegLocate,strUserInput,"REG_SZ"
'Lets you know it worked
MsgBox "Your Duration has Changed Successfully"
'Ends the script
WScript.Quit
End if
End Function
'Calls the function to run the script
Dim result
result = InputCheck(strUSerInput)

jklann

Simple Computer Pranks

Alright so everyone these days has a computer whether it is a personal computer, a work computer or even a school computer, and without jokes and pranks our day to day tasks on these machines can become boring and mundane. So to brighten up your work or school day a bit I have taken the initiative and created a few prank scripts that will really throw your colleagues off there game and provide a laugh for everyone.

Now on school and work computers most IT departments block installing third party programs as they might be malicious so to get around these security blocks I created these scripts in VBS which is allowed on almost all work computers. Keep in mind that sense this is in VBS it will only work on Windows machines.

Step 1:
Just copy and paste one of the scripts below into notepad or a text editor and save it as ‘whateveryouwant‘.vbs on your victims computer. (without the quotes).

Step 2:
Once saved (hopefully in a hidden location) just double click the file you just created and the prank has begun.

Step 3:
To end any of this pranks just go to the process section of task-manager and end the task ‘wscript.exe’. If you dont have access to task-manager just repeat the above process for the Kill code listed below.

Prank 1: Random Caps-lock
So the first prank is the the random caps-lock program what this script will do is turn the caps-lock on and off at different intervals. As you can imagine this would be very annoying while writing a work email.

Option Explicit
Dim wshShell
Set wshShell= CreateObject("WScript.Shell")
Do
WScript.sleep 1000 '10 seconds
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 500
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 200
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 1500
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 700
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 1000
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 100
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 1600
wshShell.SendKeys"{CAPSLOCK}"
WScript.sleep 6000
wshShell.SendKeys"{CAPSLOCK}"
Loop

Prank 2: Muter
This prank the permanent muting script has so far been only tested on windows seven and will be updated for older versions of windows shortly. What this prank does is set the volume of all the playback devices (speakers) to zero then kills the volume control app so they can not turn the volume back up. An exception to this program is if their keyboard has volume controls. Although if someone is blasting some horrible music,podcast,etc… this can be very useful to bring some peace and quite to your work day. This script will continue to be updated as testing continues.

Option Explicit
Dim wshShell
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
'process to kill
strProcessKill = "'SndVol.exe'"
'opens process
Set wshShell= CreateObject("WScript.Shell")
wshShell.Run "SndVol"
WScript.sleep 500
'this lowers the volume all the way down on all devices
wshShell.SendKeys"{END}"
WScript.sleep 500
'this loop just kills the process of the volume control untill this program is ended
Do
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
Loop

Automatic Shutdown:
This code can be quite evil, I would recommend that you only use this prank on your enemies. Now what you want to do is follow the steps above except now you are going to save it to their startup folder. This can be easily found by opening the “windows menu”, clicking “all programs”, then scroll down until you find the folder labeled “startup”. From here right click on the Startup folder and click “open”, this is where you want to save the file. What this does is every time your victim turns on their computer it will execute the shutdown vbs file and shutdown their computer. An even more evil alternative is to use a restart code so this will put the computer into a loop of restarting over and over again, that code is also posted below.

Shutdown code:
Set WSHShell = WScript.CreateObject("WScript. Shell")
WSHShell.Run "%windir%\system32\shutdown.exe -s -t 360"
wscript.quit

Restart code:
Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"

Program Blocker:
What this script does is allow you to block almost any program you want from running on your victims computer. So in my example I will be blocking Firefox from running.

Step 1:
Follow the above steps for the code below.

Step 2:
Choose a program you would like to block. So in my case it will be Firefox so go ahead and open your selected program.
firefox

Step 3:
Open task-manager and right-click on your selected program and click “go to process”.
task manager

Step 4:
From here you will need to copy the “Image Name”, in my case it is firefox.exe.
Image Name

Step 5:
Now that you have the Image Name of your selected program just put this in the code below where it says firefox.exe.
code

Note:
If you do not have access to task-manager, you can do a simple Google search for your programs process name.

Blocking Script:

Option Explicit
Dim wshShell
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
Dim i
strComputer = "."
'process to kill
strProcessKill = "'firefox.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
i=0
WScript.sleep 1000
Do while i < 10000 Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcess = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = " & strProcessKill ) For Each objProcess in colProcess If strProcessKill = strProcessKill Then objProcess.Terminate() Else return true End If Next i = i + 1 Loop

Kill Script:
This script will kill any of the above pranks.

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = "."
strProcessKill = "'wscript.exe'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
WScript.Quit

Notice:
More pranks will be posted soon so come check out the updates. A few of the pranks to come are the automatic shutdown, random cd tray opener, random text insertion, flashing keyboard lights, task-manager blocker, and much more. Feel free to post suggestions, questions, and opinions and ill get back to you as soon as possible.

jklann