Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sylvain Le Courtois

« Newer Snippets
Older Snippets »
Showing 1-10 of 10 total  RSS 

Perl : scan a list of networks, looking for hosts responding on the port 80 (http)

// Input : a list of address of routers, in dotted decimal notation
use strict;
use Net::Ping;
use IO::Socket::INET;

sub isodate() {
        my ($day, $mon, $year, $hour, $min, $sec) = (localtime)[3, 4, 5, 2, 1, 0];
        $mon++; # 0-based index
        $year = $year + 1900;
        my $date = sprintf ("%04i-%02i-%02i %02i\:%02i\:%02i", $year, $mon, $day, $hour, $min, $sec);
        return $date;
}

sub testhost {
       my $p = new Net::Ping("tcp");
       $p->{port_num}=80; 
       my @result = $p -> ping($_[0],2);
       return $result[0];
       }

sub to_dot {
	my $n = shift;
	my @decimal;
	for (1..4) {
		unshift @decimal, $n & 0xFF;
		$n >>= 8;
	}
	return join(".",@decimal);
}

my %dejavu;
open FH,"liste.txt";
while (<FH>) {
	chomp;
	my ($routeur,$mask)=split;
	
	next if $routeur !~ /\d+\.\d+\.\d+\.\d+$/ or $mask !~ /\d+\.\d+\.\d+\.\d+$/;
	
	next if defined($dejavu{$routeur});
	$dejavu{$routeur}=1;
	
	my ($o1,$o2,$o3,$o4) = split /\./,$mask;
	my $mask=$o1*256**3+$o2*256**2+$o3*256+$o4;
	my $num = $mask ^ 0xFFFFFFFF;
	$num--;

	my ($o1,$o2,$o3,$o4) = split /\./,$routeur;
	my $net=$o1*256**3+$o2*256**2+$o3*256+$o4 & $mask;
	
	#print join("|",$routeur,&to_dot($net),$num)."\n";
	
	print "Starting scanning network ".to_dot($net).", router = ".$routeur."\n";
	print "Adresses demarrant de ".to_dot($net+1)." et finissant a ".to_dot($net+$num).".\n";
	for my $i (1..$num) {
		my $host=to_dot($net+$i);
		if ( &testhost($host) ) {
			print "$host is alive\n";
			my $port=80;
			my $sock = new IO::Socket::INET (PeerAddr => $host,
					     PeerPort => $port,
					     Proto => 'tcp');
			if ($sock){
				close $sock;
				print "$port -open on $host\n";
				open OUT,">>webservers.txt";
				print OUT join("|",isodate(),$host,to_dot($net),$routeur)."\n";
				close OUT;
			}	else	{
				print "$port -closed on $host\n";
			}

		} else {
			print "$host is not responding\n";
		}
	}
}


close FH;

Excel VBA : read registry key values on a remote computer using WMI

// VBA code to paste in an module
Function ORACLEHOMES(strComputer As String)
    Const HKEY_LOCAL_MACHINE = &H80000002
    ORACLEHOMES = ""
    Dim strKeyPath
    Dim arrSubKeys
    Dim oReg
    Dim strValueName
    Dim strValue
    'strComputer = "."
    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    strKeyPath = "SOFTWARE\ORACLE"
    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
    For Each subkey In arrSubKeys
        If Left(subkey, 4) = "KEY_" Then
            strValueName = "ORACLE_HOME"
            oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey, strValueName, strValue
            If ORACLEHOMES = "" Then
                ORACLEHOMES = strValue
            Else
                ORACLEHOMES = ORACLEHOMES & ";" & strValue
            End If
        End If
    Next
End Function

Browser automation using perl LWP

// This is a sample code used to measure reports response times on a OAS application.
#!/usr/bin/perl
#
# LWP connection to the Datamart Portal
# Timing of the main reports
#

use strict;
require LWP::UserAgent;

my $ua = LWP::UserAgent->new;

sub isodate() {
        my ($day, $mon, $year, $hour, $min, $sec) = (localtime)[3, 4, 5, 2, 1, 0];
        $mon++; # 0-based index
        $year = $year + 1900;
        my $date = sprintf ("%04i-%02i-%02i %02i\:%02i\:%02i", $year, $mon, $day, $hour, $min, $sec);
        return $date;
}

sub datamart_login {
        my ( $user, $pass ) = @_;
        my $time_begin=time();
        my $url='http://daprd:7782/portal/page?_pageid=37,134413,37_134422&_dad=portal&_schema=PORTAL';
        my $req = HTTP::Request->new( GET => $url );
        my $resp = $ua->request($req);
        my $loginform = $resp->content ;
        if ( $loginform !~ /Entrez votre nom utilisateur/ ) {
                die isodate()." Failed to get the logon page of the Web Site\n";
        } else {
                my $locale="";
                my ($v) = $loginform =~ /NAME=\"v\" value=\"(.+)\"/;
                my ($site2pstoretoken) = $loginform =~ /NAME=\"site2pstoretoken\" value=\"(.+)\"/;
                my ($submiturl) = $loginform =~ /form method=\"POST\" action=\"(.*?)\"/;
                $resp = $ua->post( $submiturl,
                   [
                     ssousername => $user,
                     password => $pass,
                     v => $v,
                     locale => $locale,
                     site2pstoretoken => $site2pstoretoken
                   ],
                );
                $resp = $ua->get($url);
                $resp = $ua->get($url);
                if ( $resp->content !~ /Crit..res de recherche/ ) {
                        die isodate()." Failed to get the main page of Portal\n";
                }
        }
        print join(";",isodate(),"Time to log on the Portal",time()-$time_begin,$url)."\n";
}

sub datamart_testurl {
        my ($label,$url,$expected)=@_;
        my $time_begin=time();
        my $resp;
        $resp = $ua->get($url);
        $resp = $ua->get($url) if $resp->content !~ /$expected/;        # We try two times !
        if ( $resp->content !~ /$expected/ ) {
                print STDERR isodate()." Test Failed on $label. $expected not found in response.\n";
                print STDERR $resp->as_string;
        } else {
                print join(";",isodate(),$label,time()-$time_begin,$url)."\n";
        }
}

$ua->timeout(1200);
$ua->cookie_jar({});
$ua->agent( 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' );
#push @{ $ua->requests_redirectable }, 'POST';

# >>>> Main code here

datamart_login("xxxx","xxxx");

open FH,"/exploit/scripts/appli/check_datamart.ini" or die "Unable to open check_datamart.ini";
while (<FH>) {
        chomp();
        my ($report,$expected,$url) = split /;/;
        datamart_testurl($report,$url,$expected);
}
close FH;

# <<<< Main code here

Internet Explorer automation using win32::OLE

// Sample code used for one of my client
#!/usr/bin/perl -w

use strict;
use Data::Dumper;
use Win32::OLE qw( EVENTS );

my ($day, $mon, $year, $hour, $min, $sec) = (localtime)[3, 4, 5, 2, 1, 0];
$mon++; # 0-based index
$year = $year + 1900;
my $date = sprintf ("%04i-%02i-%02i %02i\:%02i\:%02i", $year, $mon, $day, $hour, $min, $sec);

my $Disconnect;
my $Menu;
my $TreeView;
my $WatchDog;
my $MenuClicked=0;

my $ScenarioCompleted=0;

my @TreeViewLinks=("Appareillage du B","Branchement Comptage","Branchement individuel");
my $Previouslink=$TreeViewLinks[0];

my $ie = Win32::OLE->new( 'InternetExplorer.Application' ) or die "error starting IE";
$ie->{visible} = 1;

Win32::OLE->Option( Warn => 3 );

$WatchDog=time();
Win32::OLE->WithEvents( $ie, \&Event, 'DWebBrowserEvents2' );
$ie->navigate( 'http://www.xxx.fr' );
Win32::OLE->MessageLoop();
unlink("noemis.err") if -f "noemis.err";
if ( ! $ScenarioCompleted ) {
	open( ERR , ">noemis.err" ); 
	print ERR "Problem executing Noemis scenario, please check www.xxx.fr.\n" ;
	close(ERR);
}
$Disconnect->Click();
Win32::OLE->SpinMessageLoop;

# Maintenance du fichier historique
open ( STATS , "noemis.txt" );
my @lines=<STATS>;
close (STATS);
open( STATS , ">noemis.txt" ); 
for my $line (@lines) {
	my ($datetime) = split ( /;/ , $line );
	my ($h_year,$h_mon) = $datetime =~ /^([0-9]{4})-([0-9]{2})/;
	print STATS $line if ($year*12+$mon) - ($h_year*12+$h_mon) < 2;
}
print STATS join(";",$date,"Noemis Scenario",( time() - $WatchDog ))."\n";
close( STATS );

sleep 2;
Win32::OLE->SpinMessageLoop;
sleep 1;
$ie->Quit();
exit 0;


sub Event {
	my ($Obj,$Event,@Args) = @_;
	my $IEObject = shift @Args;
	print " Event triggered: $Event\n";    

	my ($i,$anchor);
	my $anchors;
    
	# STEP 1 : Find the main menu, login to the web site, find the treeview
	if ($Event eq "DocumentComplete") {    
		print "URL: " . $IEObject->Document->URL . "\n";
		if ( $IEObject->Document->URL eq "http://www.xxx.fr/ident.aspx" ) {
			my $forms = $IEObject->Document->forms;
			my $form = $forms->item(0);
			if ( defined($form->elements("fldNumCli")) ) {
				print "--------------------------------------------\n";
				print "Found the login box, authenticating ...\n";
				print "--------------------------------------------\n";
			    $form->elements("fldNumCli")->{value} = "xxxx";
			    $form->elements("fldUtil")->{value} = "xxx";
			    $form->elements("fldPwd")->{value} = "xxx";
		    	$form->elements("btIdent")->Click();
	    		}
		}
		if ( $IEObject->Document->URL eq "http://www.xxx.fr/menu.aspx" ) {
			print "Found the menu.\n";
			$Menu = $IEObject->Document;
			$anchors = $IEObject->Document->links;
			for (my $i=0; $i < $anchors->length; $i++) {
				$anchor = $anchors->item($i);
				print $anchor->href."\n";
				$Disconnect = $anchor if $anchor->href eq "http://www.xxx.fr/ident.aspx?qs=deconnecter";
			}
	      	}	    
		if ( $IEObject->Document->URL eq "http://www.xxx.fr/client/frameTreeview.aspx" ) {
			print "Found the TreeView.\n";
			$TreeView = $IEObject->Document;
      		}		
	}

	# STEP 2 : Click on the Menu and TreeView links   
	if ($Event eq "DocumentComplete") {    		
	if ( ! $MenuClicked and defined($Menu) ) {
		my $MenuItem = $Menu->getElementById("SM_CLIE_RECH");
		if ( defined($MenuItem) ) { 
			print $MenuItem->ID."\n";
			$MenuItem->Click;
			$MenuClicked = 1;
		}
	}}

	if ( $Event eq "CommandStateChange" or $Event eq "StatusTextChange" ) {
		print Dumper($IEObject);
	}
	if ( @TreeViewLinks != 0 and 
	     defined($TreeView) and 
	     $Event eq "DocumentComplete" 
	) {
		my $link = shift(@TreeViewLinks);
		$anchors = $TreeView->links;
		my $found=0;
		print "Looking for '$link' in the TreeView ... \n";
	        for (my $i=0; $i < $anchors->length; $i++) {
		       	$anchor = $anchors->item($i);
	        	#print $anchor->innerHTML."\n";
		       	if ( $anchor->innerHTML =~ /$link/ ) {
				print "Clicking on '$link' ... \n";
	                	$anchor->Click;
				$found=1;
				$Previouslink=$link;
				last;
			}
	        }
		if ( ! $found ) { 
			# Le TreeView a bugge, on reclique
			sleep 1;
			print "Looking for '$Previouslink' in the TreeView ... \n";
		        for (my $i=0; $i < $anchors->length; $i++) {
			       	$anchor = $anchors->item($i);
	        		#print $anchor->innerHTML."\n";
		       		if ( $anchor->innerHTML =~ /$Previouslink/ ) {
					print "Clicking on '$Previouslink' ... \n";
	              		  	$anchor->Click;
					last;
				}
		        }
			unshift @TreeViewLinks,$link;
		}
	} 
   
	# STEP 3 : Verify the list displayed 
		
	if ($Event eq "DocumentComplete") {    
   		if ( @TreeViewLinks == 0 and $IEObject->Document->URL =~ /listeRefPlof.aspx/ ) {
			print "Scenario completed, exiting ...\n";
			$ScenarioCompleted=1;
	   		Win32::OLE->QuitMessageLoop;
		}
	}
    

	# Exit on errors
	    
	Win32::OLE->QuitMessageLoop() if $Event eq "OnQuit" or time() > $WatchDog + 60;
    
}

ASP Page listing and making changes to AD accounts

// Used for automated AD account migration
<HTML><HEAD><TITLE>Workstation User Account migration</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
href="files/v2006.css" type=text/css rel=stylesheet>
<BODY leftMargin=0 topMargin=30 marginwidth="0" marginheight="0">
<CENTER>
<%
' ------------------------------------------------------------------------
Const ADS_PROPERTY_CLEAR = 1

Const SOURCE_OU="ou=NT Users,ou=NT,dc=fr,dc=erm,dc=int"
Const TARGET_OU="ou=SUPPORT SERVICES,dc=fr,dc=erm,dc=int"

Const HOMES_PATH="\\frsrvfil0001\USERS\"
Const PROFILES_PATH="\\frsrvfil0001\PROFILES\"

Const ADMIN_HOMES_PATH_SOURCE="\\frsrvfil0001\U$\NT\"
Const ADMIN_PROFILES_PATH_SOURCE="\\frsrvfil0001\P$\NT\"
Const ADMIN_HOMES_PATH_DEST="\\frsrvfil0001\U$\"
Const ADMIN_PROFILES_PATH_DEST="\\frsrvfil0001\P$\"

Const SCRIPT_NAME="ntuser_to_xp.asp"

Dim State
State="Init"
Dim OU, Member
 
If Request.QueryString("login") <> "" Then
		' Affichage formulaire pour modif du compte
		State="Info"
End If
If Request.Form("login") <> "" Then
		' On a cliqué sur OK pour valider le formulaire
		State="Modify"
End If
' ------------------------------------------------------------------------
%>
<TABLE cellSpacing=0 cellPadding=1 width=500 align=center bgColor=#26333e 
border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=1 width=500 align=center border=0>
        <TBODY>
        <TR bgColor=#f0f3f5>
          <TD width=160 valign="top"><IMG height=116 src="files/man_portable.jpg" 
            width=160> </TD>
          <TD width=302 bgColor=#e5ebef>

<%
	If State="Init" Then
	'-----------------------------------------------------------------------------------
	' Listing of the NT Users
	'-----------------------------------------------------------------------------------
%>          

            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=3 height=22>
                    <%
                    'Response.Write(SOURCE_OU & "<BR>") 
                    %>
					Please select the NT 4.0 Workstation user account to migrate
                </TD></TR>
                
              <TR>
                <TD class=td11 height=22>
                                  <%
                  Set OU = GetObject("LDAP://" & SOURCE_OU)
                  OU.Filter = Array("user")
    	          For Each Member In OU
    	          		' Bug with the SMS Account ??
    	          		If Member.Name <> "CN=SMSService" Then 
    	          		If Member.AccountDisabled = 0 Then
	    	                Response.Write("<A HREF=""" & SCRIPT_NAME & "?login=" & Server.URLEncode(Member.Name) & """>" & Member.FullName & "</A><BR>")
	    	            End If
	    	            End If 
            	  Next      
                  
                  %>

                </TD>
                </TR>
                
                </TBODY></TABLE>

<%
End If
%>                
                
<%
	If State="Info" Then
	'-----------------------------------------------------------------------------------
	' Information page about the NT Users
	'-----------------------------------------------------------------------------------
%>          
			<FORM method=post>

            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=2 height=22>
                 	<%
                 	Response.Write("Windows NT 4.0 User Account Migration")
                    %>
					
                </TD></TR>
               
                  <%
                  Sub TabRow(v1,v2)
                  		Response.Write("<TR class=td11 height=16><TD><B>" & v1 & "</B>")
                  		Response.Write("<TD>" & v2 & "</TD>")
                  		Response.Write("</TD></TR>")
                  End Sub
                  Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)

                  TabRow "User Name",Member.FullName
                  TabRow "NT Login",Member.sAMAccountName
				  TabRow "Login Script", Member.LoginScript & " (to delete)"
				  TabRow "Profile Path", Member.Profile
				  TabRow "New Path",PROFILES_PATH & Member.sAMAccountName
				  TabRow "Home Folder", Member.HomeDirectory
				  TabRow "New Path",HOMES_PATH & Member.sAMAccountName
				  
				  ' Liste des OU dans SUPPORT SERVICES
 				  Dim OUSuppServices, Entity, BoxList
 				  Set OUSuppServices=GetObject("LDAP://" & TARGET_OU)
				  OUSuppServices.Filter = Array("organizationalUnit")
				  BoxList="<SELECT NAME=""entity"">"
				  For Each Entity in OUSuppServices
				  	BoxList= BoxList & "<OPTION VALUE=""" & Entity.Name & """>" & Mid(Entity.Name,4) & "</OPTION>"
				  Next
				  BoxList=BoxList & "</SELECT>"
				  TabRow "Organizational Unit",BoxList
                                    
                  %>

                
                </TBODY></TABLE>
                <BR>
                <INPUT name=login type=hidden value=<% Response.Write(Member.sAMAccountName) %> >
                <INPUT type=image height=18 alt="GO !" width=15 src="files/submit.gif" value=login border=0 name=ok>
                &nbspCliquer ici pour migrer ce compte.<BR><BR>
                ATTENTION, l'utilisateur ne doit pas être connecté ! 
                <% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour annuler" & "</A><BR>") %>
                </FORM>

<%
End If
%>                

<%

	If State="Modify" Then
	'-----------------------------------------------------------------------------------
	' Migration of the NT Users
	'-----------------------------------------------------------------------------------
Sub dirMoveTree(source, dest)
	Response.Write "Deplacement de <B>" & source & " vers " & dest & "</B><BR>"
	Dim Folder,File,SubFolder
	set Folder=fso.GetFolder(source)
	For Each File In Folder.Files
	      Response.Write File.Name & " File -> " & dest & "<BR>"
	      file.move dest & "\"
	Next
	For Each SubFolder In Folder.SubFolders
	      Response.Write SubFolder.Name & " Folder -> " & dest & "<BR>"
	      SubFolder.move dest & "\"
	Next
End Sub

%>          
<CENTER>
Windows NT 4.0 User Account Migration<BR><BR>
<%

' Modification des proprietes l'utilisateur dans AD
Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)

' ADS_PROPERTY_CLEAR
Member.PutEx 1, "scriptPath", 0
Member.SetInfo

Member.Put "profilePath", PROFILES_PATH & Member.sAMAccountName
Member.Put "homeDirectory", HOMES_PATH & Member.sAMAccountName
' 
Member.SetInfo
' 
Response.Write("Utilisateur <B>" & Member.sAMAccountName & "</B> Modifié dans AD<BR><BR>")

' Deplacement dans le bon conteneur
Set OU = GetObject("LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU)
OU.MoveHere "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU, Request.QueryString("login")
Response.Write("Utilisateur <B>" & "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU & "</B> Deplacé dans " & "LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU & "<BR><BR>")

DIM fso, File, Folder, SubFolder
Set fso = CreateObject("Scripting.FileSystemObject")

' Creation des repertoires cible

fso.CreateFolder(ADMIN_HOMES_PATH_DEST & Request.Form("login"))
fso.CreateFolder(ADMIN_PROFILES_PATH_DEST & Request.Form("login"))

' Deplacement des données

dirMoveTree ADMIN_HOMES_PATH_SOURCE & Request.Form("login"),ADMIN_HOMES_PATH_DEST & Request.Form("login")
dirMoveTree ADMIN_PROFILES_PATH_SOURCE & Request.Form("login"),ADMIN_PROFILES_PATH_DEST & Request.Form("login")

' Applications des ACLs, en arriere plan car ca peut etre long !
Response.Write("<BR>Creation du script d'application des ACLs C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd<BR><BR>")
Set server_shell = Server.CreateObject("wscript.shell")

server_shell.Run "cmd /c echo echo Excecution Cacls >C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_HOMES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":C /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_PROFILES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":F /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1

' server_shell.Run "C:\Inetpub\wwwroot\techcity\xcacls.cmd >C:\Inetpub\wwwroot\techcity\xcacls.log 2>&1",,1
Response.Write("<BR>Les ACLs seront appliquee dans 5 min (scheduled)...<BR><BR>")
Response.Write("Attendre egalement la fin de replication de AD ...<BR><BR>")

Response.Write("<BR>Terminé !<BR>")

%>
<% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour quitter" & "</A><BR>") %>
</CENTER>
<%
End If
%>                


              </TD></TR>            
                
                </TBODY></TABLE></TD></TR>
                        
                
</TBODY></TABLE></CENTER></BODY></HTML>

Simple ASP page to reset passwords

// This page allows to reset an AD account password.
<HTML><HEAD><TITLE>Reinitialisation de mot de passe</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
href="files/v2006.css" type=text/css rel=stylesheet>
<BODY leftMargin=0 topMargin=30 marginwidth="0" marginheight="0">
<FORM method=post>
<CENTER>
<TABLE cellSpacing=0 cellPadding=1 width=500 align=center bgColor=#26333e 
border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=1 width=500 align=center border=0>
        <TBODY>
        <TR bgColor=#f0f3f5>
          <TD width=160><IMG height=116 src="files/man_portable.jpg" 
            width=160> </TD>
          <TD width=302 bgColor=#e5ebef>
            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=3 height=22>
                <%
                If Request.Form("login") = "" Then
                	Response.Write("<B>Saisir le compte à reinitialiser</B>")
                Else
                    Dim Group, Member, Domain, UserFound
                    ' 
                    Domain ="FR-ERM"
                    '
                    UserFound=0
                    
	                Set Group = GetObject("WinNT://" & Domain & "/Domain Users")
    	            For Each Member In Group.Members
    	            	' Response.Write(Member.Name & "<BR>")
        	        	If UCase(Member.Name) = UCase(Request.Form("login")) Then
        	        		UserFound=1
        	        		If Member.AccountDisabled Then 
        	        			Response.Write(" " & Request.Form("login") &" est un compte desactive</B>")
        	        			Exit For
        	        		Else
        	        			' Essai de reinit de mot de passe
        	        			Dim res
        	        			res=Member.SetPassword(Request.Form("pass"))
        	        			'Member.Put "pwdLastSet", CLng(0)
        	        			Member.Put "PasswordExpired", 1
								Member.SetInfo
        	        			Response.Write("<B>L'utilisateur "& Request.Form("login") & " a changé de mot de passe !<BR><BR></B>Il devra changer de mot de passe au prochain login.")
        	        			Exit For
        	        		End If
        	        	End If 
            	    Next      
       	        	If UserFound = 0 Then
       	        		Response.Write(Request.Form("login") &" non trouvé dans le domaine "& Domain)
       	        	End If           	            	
                	
                End If
                %>
              
                </TD></TR>
              <TR>
                <TD class=td11 width="1%" height=22>Identifiant
               
                </TD>
                <TD class=td11 colSpan=2>Nouveau mot de passe</TD></TR>
              <TR>
                <TD width="25%"><INPUT maxLength=20 name=login>
 
                </TD>
                <TD width="20%"><INPUT type=password maxLength=10 size=10 
                  name=pass> </TD>
                <TD><INPUT type=image height=18 alt="Reset !" width=15 
                  src="files/submit.gif" value=login border=0 name=ok> 
                </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></FORM></BODY></HTML>

Excel : Make a query on a Oracle database and return the result (useful for sheet formulas)

// This should be pasted in a module of the workbook
Function ORAQUERY(strHost As String, strDatabase As String, strSQL As String, strUser As String, strPassword As String)
  Dim strConOracle, oConOracle, oRsOracle
  Dim StrResult As String
  
  StrResult = ""
  
  strConOracle = "Driver={Microsoft ODBC for Oracle}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=" & strHost & ")(PORT=1521))" & _
         "(CONNECT_DATA=(SERVICE_NAME=" & strDatabase & "))); uid=" & strUser & " ;pwd=" & strPassword & ";"
  Set oConOracle = CreateObject("ADODB.Connection")
  Set oRsOracle = CreateObject("ADODB.Recordset")
  oConOracle.Open strConOracle
  Set oRsOracle = oConOracle.Execute(strSQL)
  Do While Not oRsOracle.EOF
      If StrResult <> "" Then
        StrResult = StrResult & Chr(10) & oRsOracle.Fields(0).Value
      Else
        StrResult = oRsOracle.Fields(0).Value
      End If
    oRsOracle.MoveNext
  Loop
  oConOracle.Close
  Set oRsOracle = Nothing
  Set oConOracle = Nothing
  ORAQUERY = StrResult
End Function

Simple output of date in perl

// Simple output of current date in perl

  my @day_name = ("Sun.","Mon.","Tue.","Wed.","Thu.","Fri.","Sat.");
  my ($sec,$min,$hour,$mday,$mon,$year,$wday); 
  ($sec,$min,$hour,$mday,$mon,$year,$wday,undef,undef)=localtime(time()); $year+=1900;$mon++;
  $report_date=sprintf("%s %04d.%02d.%02d %02d:%02d",$day_name[$wday],$year,$mon,$mday,$hour,$min);

CMD text file rotation 60 generations

// Simple CMD text file rotation 60 generations
@echo off

if not exist %1.txt goto :EOF
if exist %1_62.txt del %1_62.txt

if exist %1_60.txt ren %1_60.txt %1_61.txt
if exist %1_59.txt ren %1_59.txt %1_60.txt
if exist %1_58.txt ren %1_58.txt %1_59.txt
if exist %1_57.txt ren %1_57.txt %1_58.txt
if exist %1_56.txt ren %1_56.txt %1_57.txt
if exist %1_55.txt ren %1_55.txt %1_56.txt
if exist %1_54.txt ren %1_54.txt %1_55.txt
if exist %1_53.txt ren %1_53.txt %1_54.txt
if exist %1_52.txt ren %1_52.txt %1_53.txt
if exist %1_51.txt ren %1_51.txt %1_52.txt
if exist %1_50.txt ren %1_50.txt %1_51.txt
if exist %1_49.txt ren %1_49.txt %1_50.txt
if exist %1_48.txt ren %1_48.txt %1_49.txt
if exist %1_47.txt ren %1_47.txt %1_48.txt
if exist %1_46.txt ren %1_46.txt %1_47.txt
if exist %1_45.txt ren %1_45<