Showing posts with label pinoy scripts. Show all posts
Showing posts with label pinoy scripts. Show all posts

Monday, June 18, 2007

ADSI Kixtart UDF for Citrix login

Having a mixed mode environment gave us a lot of hassle when logging in to NT and querying group membership in AD... Specially in our case, we have nested OU's...

Ifmember.exe is useful for this problem but it does cause a slight delay in the login process and the users are complaining on the slow login session, some couldn't wait and cancels the connection... catastrophic experience ends up as a global complain... hmmm... some people are just impatient...

So to be able to execute an ADSI query through kix login script the function below can be inserted anywhere in the login script to perform InGroup query... or this can fully replace the built in InGroup function in kixtart.


Code Snippet:

  1. Function fnInGroupAD($sGroup,Optional $bComputer)
  2. Dim $objSys,$objTarget,$aMemberOf,$sMemberOf
  3. $objSys = CreateObject("ADSystemInfo")
  4. $objTarget = GetObject("LDAP://"+Iif($bComputer,$objSys.ComputerName,$objSys.UserName))
  5. $aMemberOf = $objTarget.GetEx("memberOf")
  6. For Each $sMemberOf in $aMemberOf
  7. If InStr($sMemberOf,"CN="+$sGroup+",")
  8. $fnInGroupAD = Not 0
  9. Exit
  10. EndIf
  11. Next
  12. $fnInGroupAD = NOT 1
  13. EndFunction

If at first you fail, call it version 1.0

Wednesday, June 13, 2007

String manipulation in NT scripts

I was working on a Citrix Login script and found out most clients are not able to perform WMI queries to get session information from the server or just simple evironment variable expansion... or is it just our GPO is just too tight?

Instead of using vbscript for the string manipulation, I opted to the old school NT scripting, since the built in usrlogon script in PS4 is native to NT.

So I searched the help files and the net for old DOS commands for string manipulation as my goal for this script is to get the first 2 characters from the environment variable %CLIENTNAME%. If the machine name's first 2 characters are "UK", then a certain drive is required to be mapped.

Now, It is possible to retrieve specific characters from a string variable.

Syntax:
%variable:~num_chars_to_skip%
%variable:~num_chars_to_skip,num_chars_to_keep%

This can include negative numbers:
%variable:~num_chars_to_skip, -num_chars_to_skip%
%variable:~-num_chars_to_skip,num_chars_to_keep%

A negative number will count backwards from the end of the string. In Windows NT 4 the syntax for negative numbers was not supported.

Examples:
The variable _test is used for all the following examples:

SET _test=123456789abcdef0

::Extract only the first 5 characters

SET _result=%_test:~0,5%
ECHO %_result% =12345

::Skip 7 characters and then extract the next 5

SET _result=%_test:~7,5%
ECHO %_result% =89abc

::Skip 7 characters and then extract everything else

SET _result=%_test:~7%
ECHO %_result% =89abcdef0

::Extract only the last 7 characters

SET _result=%_test:~-7%
ECHO %_result% =abcdef0

::Extract everything BUT the last 7 characters

SET _result=%_test:~0,-7%
ECHO %_result% =123456789

::Extract between 7 from the front and 5 from the end

SET _result=%_test:~7,-5%
ECHO %_result% =89ab

::Go back 7 from the end then extract 5 towards the end

SET _result=%_test:~-7,5%
ECHO %_result% =abcde

::Extract between 7 from the end and 5 from the end

SET _result=%_test:~-7,-5%
ECHO %_result% =ab

And this is the final script:
SET _CNAME=%CLIENTNAME%
CALL SET _ORIGIN=%_CNAME:~-0,2%

IF %_ORIGIN% EQU UK (
NET USE R: \\UKFILSERVER\CITRIX$
) ELSE (
GOTO Done
)

:Done

If at first you fail, call it version 1.0

Monday, June 11, 2007

Viral detection on multiple page loads

Aside from having too much page loads detected as being viral, too much query from a single point of origin is also detected as viral... now this is the time that when the search results will prompt you for message that this query format is detected as virus and will ask you to key in the confirmation code to confirm that it was a valid search query.

Anyway, since ie will just crash your machine when performing too much page load and queries, I have written another scriptlet that utilizes MSXML2.ServerXMLHTTP.4.0 instead, so no api calls are made to unreliable but wonderfully obedient ie.

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.4.0")

'::::: Set your proxy here, comment it if not required


xmlhttp.setProxy 2,"10.1.1.1:8080"

'::::: Open the url using http Get

xmlhttp.open "GET", purl, false

You may use the following as part of your query URL:

InURL:Index.Of?mp3 InText:Index.Of?mp3 InTitle:Index.Of?mp3 InURL:Top Keywords InText:Top Keywords InTitle:Top Keywords InURL:scripts InText:scripts InTitle:scripts InURL:niche InText:niche InTitle:niche InURL:adsense InText:adsense InTitle:adsense InURL:income InText:income InTitle:income InURL:3gp InText:3gp InTitle:3gp InURL:hotel InText:hotel InTitle:hotel InURL:travel InText:travel InTitle:travel InURL:medicine InText:medicine InTitle:medicine InURL:new InText:new InTitle:new InURL:best InText:best InTitle:best InURL:rare InText:rare InTitle:rare InURL:free InText:free InTitle:free InURL:finance InText:finance InTitle:finance InURL:movie InText:movie InTitle:movie InURL:download InText:download InTitle:download InURL:source InText:source InTitle:source InURL:game InText:game InTitle:game InURL:music InText:music InTitle:music InURL:audio InText:audio InTitle:audio InURL:film InText:film InTitle:film InURL:digital InText:digital InTitle:digital InURL:flight InText:flight InTitle:flight InURL:school


':::::: Make sure you define your Browser Agent or else queries will not be allowed and will prompt you for blocks of code that you might need to submit to rectify the malformed query.

xmlhttp.setRequestHeader "User-Agent","Microsoft Internet Explorer"


xmlhttp.send()


':::::: You can do anything with the search results, follow the links, blah
WScript.Echo xmlhttp.responseText

set xmlhttp = nothing


If at first you fail, call it version 1.0

Why Click it, If you can script it?

While 10,000 ecpm can earn you $0.40, one wonders how much it takes to actually earn...

A sequel to my previous post on my recent fascination on ecpm, page loads doesn't mean much if either the page loads are in millisecond and no links in the pages are clicked or the search option was utilized...

Adding an extra function allows the page loads to have a little extra sense as not only page loads will be peformed, but hey... even the search option is populated with a query string (maybe from an array, etc...)... and an added trick to perform the click to actually perform the query...

To fill up the input for the search utility:
.Document.All.tags("INPUT")("q").Value = searchKey

To Click the search button:
Set sButt = .Document.getElementsByTagName("INPUT")
For Each Butt in
sButt
If LCase(Butt.getAttribute("value")) = "search" Then
Butt.Click
Exit For
End If
Next

If this makes sense and actually is acceptable, why not click on all the links in the result page to add up to your ecpm queries...

Set xLinx = .Document.getElementsByTagName("a")
For Each Linx In xLinx
Linx.Click
Next

Note: Make sure that your site setting is to load the results in the same page, rather than popping up new windows... or else you will flood your screen with tons of ie windows... hahaha... (this, even if .visible=0)

A terminate process will help in getting rid of all the unwanted window popups:

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'Iexplore.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

Note: Do this after each page finishes loading after the click.

A draw back is that all your cookies and such are tracked, hence after numerous reloads and queries it might be detected as a viral activity, solution... clear your tracks...

First, get you cache path from your registry:
CachePath = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\Directory")

Then parse through the folders to delete all cache:
Set rootFolder = fso.GetFolder(CachePath)
Set subFolders = rootFolder.SubFolders
For Each folder in subFolders
fso.DeleteFolder(folder)
Next

You may reuse the same to delete the remaining files in the rootfolder. Just replace .SubFolders to .Files.

There you go...

As easy as it looks like and as cool as it may seem, this will not guarantee that you will actually earn anything based on pageloads and queries... ecpm is not as easily attainable although your site is now generating billions of pageloads\month...

And knowing how M$oft Internet Explorer sucks bigtime, you know that it will crash alot if you execute this like 10,000 times????

Anyway, I use Opera and Firefox 50/50... I only use IE to test my scripts to see how long it will take to crash it...

Good luck!

If your first attempt fails, call it version 1.0

Tuesday, June 05, 2007

1,000 eCPM can earn you only $0.01

Just a script that does nothing but loads a page repeatedly...
Hmmm... might be useful or not useful...
Can It be used to accumulate eCPM?

Totally up to you...

psURL = "Your desired url..."
psURL2 = "Second desired url..."
Dim x
Dim IE

x=0
Set IE = CreateObject("InternetExplorer.Application")

With IE
.menubar=0

.toolbar=0
.statusBar=0
.navigate psURL
.visible=0
.resizable=1
Do while .busy
Loop

Do While x < "desired amout of page loads"
WScript.Echo Now & " - Count Load: " & x
.navigate2 psURL
WScript.Echo Now & " - Loaded: " & psURL
Do while .busy
Loop

x =x + 1
WScript.Echo Now & " - 15sec sleep..."
WScript.Sleep(15000)
.navigate2 psURL2
WScript.Echo Now & " - Loaded: " & psURL2
Loop
End With




Thursday, May 24, 2007

SMTP using .NET Classes (Powershell)

A great Powershell code that you can use as a template for SMTP mail with authentication.

Easily extendible for Web development.


Scriptlet:
###############################################
$mail = new-object System.Net.Mail.MailMessage

#set sender email address
$mail.From = new-object System.Net.Mail.MailAddress("mymail@mydomain.com");

#set the recepient email address
$mail.To.Add("touser@domain.com");

#set the email subject
$mail.Subject = "";

#set the content

$mail.Body = "";

#send the message
$smtp = new-object System.Net.Mail.SmtpClient("mydomain.com");

#set the username and password properites on the SmtpClient for authentication
$smtp.Credentials = new-object System.Net.NetworkCredential("username", "password");

#send it
$smtp.Send(mail);


#Voila!
###############################################


Monday, May 21, 2007

Powershell Lynx Project

Those were the days of Lynx when you used to browse the web as text thru the console...

My previous blogs were about scripting with Yahoo api search services. Well, since blogging at work is not really encouraged, I have decided to create my powershell version of Lynx. Since I'm scripting most of the time due to adHoc script requests, my boss won't even realize that I'm actually blogging... hehehe...

For starters, a scriptlet that navigates IE:

$ie = New-Object -com InternetExplorer.Application
$ie.Visible=$true
$ie.MenuBar=$false
$ie.ToolBar=$false
$ie.StatusBar=$false
$ie.Navigate("http://26thgstreet.blogspot.com")


Visibility of IE can be set to false later after I finalized the function to get the HTMLDocument.Innertext and write it to the console.

I will aso have to create a function to accept console arguments to be posted to the HTMLDocument so that I can update my blogs...

Stay tuned for the script updates.



Free PowerShell Book

My msdn feeds shed some light on my powershell addiction after receiving the good news.

It's finally out, thanks to Frank Koch.


The subtitle is "An introduction to scripting technologies for people with no real background knowledge". Read more.

Get it here.


Friday, May 18, 2007

Yahoo Search Script

Something to share...

Using MsXML.DOMDocument, you will be able to query Yahoo! API (
http://api.search.yahoo.com/WebSearchService/V1/webSearch?) .

Query Parameters used:


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Yahoo Search Script
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const APP_ID = "insert your app ID"

'Grab the incoming search query or ask for one
If WScript.Arguments.Length = 0 Then
strQuery = InputBox("Enter a search Term")
Else
strQuery = WScript.Arguments(0)
End If

'Construct a Yahoo! Search Query
strLanguage = "en"
strReqURL = "http://api.search.yahoo.com/" & _
"WebSearchService/V1/webSearch?" & _
"appid=" & APP_ID & _
"&query=" & strQuery & _
"&language=" & strLanguage

'Start the XML Parser
Set MSXML = CreateObject("MSXML.DOMDocument")

'Set the XML Parser options
MSXML.Async = False

'Make the Request
strResponse = MSXML.Load(strReqURL)

'Make sure the request loaded
If (strResponse) Then

'Load the results
Set Results = MSXML.SelectNodes("//Result")

'Loop through the results
For x = 0 to Results.length - 1
strTitle = Results(x).SelectSingleNode("Title").text
strSummary = Results(x).SelectSingleNode("Summary").text
strURL = Results(x).SelectSingleNode("Url").text
strOut = (x + 1) & ". " & _
strTitle & vbCrLf & _
strSummary & vbCrLf & _
strURL & vbCrLf & vbCrLf
WScript.Echo strOut
Next

'Unload the results
Set Results = Nothing

End If

'Unload the XML Parser
Set MSXML = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Thursday, May 17, 2007

CPU Temp Probes

I have searched the web for a script that performs temperature probes but had no luck in getting the real picture until wbemtest helped me find classes not included in M$oft's Scriptomatic.

Follow the instructions below to test if the script will work on your machine for CPU temperature probe:

1. Launch wbemtest


2. Click connect


3. Change the namespace to "root\WMI" then click Connect


4. Click Query, supply the query "Select * from MSAcpi_ThermalZoneTemperature" , then click Apply


5. Double click on the result to view the class properties:


If you are able to view the results then it's ok to proceed with the scriplet.

Below is the script that probes for CPU temperature via MSAcpi_ThermalZoneTemperature. The initial results are in 10ths of degrees in Kelvin so I had to convert the results to Celcius and Farenheit.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' CPU Temperature Probe
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("Select * from MSAcpi_ThermalZoneTemperature",,48)
For Each objItem in colItems

With objItem
WScript.Echo "Active: " & .Active & vbcrlf

FarTemp = ((9/5)*((.CurrentTemperature - 2732)/10)) + 32
CelTemp = ((FarTemp - 32) * (5/9))
WScript.Echo "Current Temperature: " & vbcrlf & _
FarTemp & " (Degrees Farenheit)" &amp;amp;amp;amp;amp; _
" | " & CelTemp & " (Degrees Celcius)" & vbcrlf

FarTemp=((9/5)*((.CriticalTripPoint - 2732)/10)) + 32
CelTemp = ((FarTemp - 32) * (5/9))
WScript.Echo "Critical Temperature (Temperature at which the OS must shutdown the system): " &amp;amp;amp;amp; vbcrlf & _
FarTemp & " Degrees Farenheit" & _
" | " & CelTemp & " Degrees Celcius" & vbcrlf

If .PassiveTripPoint <> 0 Then
FarTemp=((9/5)*((.PassiveTripPoint - 2732)/10)) + 32
CelTemp = ((FarTemp - 32) * (5/9))
WScript.Echo "Passive Temperature (Temperature at which the OS must activate CPU throttling): " &amp;amp;amp;amp; vbcrlf & _
FarTemp & " Degrees Farenheit" & _
vbcrlf & CelTemp & " Degrees Celcius" & vbcrlf
End If

WScript.Echo "Thermal Stamp: " & .ThermalStamp & vbcrlf
End With
Next
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

CPU Max Temperatures

AMD Althon, Althon Opteron, Duron & Sempron Series:

  • AMD Athlon (socket) upto 1Ghz 90°C
  • AMD Athlon (slot) all speeds 70°C
  • AMD Athlon Thunderbird 1.1Ghz+ 95°C
  • AMD Athlon MP 1.33Ghz+ 95°C
  • AMD Athlon XP 1.33Ghz+ 90°C
  • AMD Athlon XP T-Bred upto 2100+ 90°C
  • AMD Athlon XP T-Bred over 2100+ 85°C
  • AMD Athlon XP Barton 85°C
  • AMD Duron up to 1Ghz 90°C
  • AMD Duron 1Ghz+ 90°C
  • AMD Duron Applebred 85°C
  • AMD Opteron 65 - 71°C
  • AMD Athlon 64 70°C
  • AMD Athlon 64 (Socket 939, 1.4 volts) 65°C
  • AMD Athlon 64 FX 70°C
  • AMD Athlon 64 X2 71°C
  • AMD Sempron (T-bred/Barton core) 90°C
  • AMD Sempron (Paris core) 70°C
  • AMD Mobile Sempron 95°C

AMD K6 Series
  • AMD K6/K6-2/K6-III (All except below) 70°C
  • AMD K6-2/K6-III (model number ending in X) 65°C
  • AMD K6-2+/K6-III+ 85°C

Intel Pentium III Series
  • Pentium III Slot 1 500-866Mhz 80°C
  • Pentium III Slot and socket 933Mhz 75°C
  • Pentium III Slot 1 1Ghz 60 - 70°C
  • Pentium III Slot 1 1.13Ghz 62°C

Intel Celeron Series
  • Intel Celeron 266-433Mhz 85°C
  • Intel Celeron 466-533Mhz 70°C
  • Intel Celeron 566-600Mhz (Coppermine) 90°C
  • Intel Celeron 633-667Mhz 82°C
  • Intel Celeron 700 - 850Mhz 80°C
  • Intel Celeron 900Mhz - 1.6Ghz 69 - 70°C
  • Intel Celeron 1.7Ghz and Higher 67 - 77°C

Intel Pentium II
  • Intel Pentium II (First Generation "Klamath") 72 - 75°C
  • Intel Pentium II (Second Generation, 266-333Mhz) 65°C
  • Intel Pentium II (350 - 400Mhz) 75°C
  • Intel Pentium II (450Mhz) 70°C

Intel Pentium 4, Pentium M (notebooks)
  • Intel Pentium 4 64 - 78°C
There are no specific stats for Pentium 4 CPU’s as P4’s have an ability to slow themselves down when they are getting too hot and thus, in theory they should never be able to burn themselves out. To get specifics consult Intel’s specifications for your particular model.

  • Intel Pentium M (notebooks) 100°C

Intel Pentium D (dual core)
  • Intel Pentium D 820 (2.8Ghz) 63°C
  • Intel Pentium D 830 & 840 (3.0 - 3.2Ghz) 69.8°C

Intel Pentium Pro
  • Intel Pentium Pro. 256 or 512K L2 Cache 85°C
  • Intel Pentium Pro. 1MB L2 Cache 80°C