Join 4Shared Now!

Scripting

Logon Scripit with style (Batch)

posted Apr 11, 2012 12:28 PM by Chris Franklin   [ updated Apr 11, 2012 12:46 PM ]

logon.bat

@echo off
Setlocal EnableDelayedExpansion

:::: Set Server(s) Name
SET _SRV1=Server1

:::: For Static Drive Letters, Set them here as fallows.
SET _DRV.company=F:
SET _DRV.construction=G:
SET _DRV.PDP=H:
SET _DRV.ILP=I:
SET _DRV.PCR=J:
SET _DRV.SP_Properties=K:
SET _DRV.Quickbooks=L:
SET _DRV.Premier QB=P:
SET _DRV.Recycle=R:
SET _DRV.farro=S:
SET _DRV.Homes\%username%=T:
SET _DRV.exec=X:

FOR %%A in (company construction PDP ILP PCR SP_Properties Quickbooks "Premier QB" Recycle farro exec Homes\%username%) DO (
 SET DRVMP=%%~A
 SET DRVLR=

 FOR /F "tokens=2* delims=.=" %%B IN ('SET _DRV.') DO (
  IF %%B==!DRVMP! SET DRVLR=%%C
 )

 IF NOT DEFINED DRVLR (
  for %%D in (Z Y X W V U T S R Q P O N M L K J I H G F E D C) do CD %%D: 1>> nul 2>&1 & if errorlevel 1 set DRVLR=%%D:
 )

 NET USE !DRVLR! /DELETE 1>> nul 2>&1
 IF EXIST "\\%_SRV1%\!DRVMP!\allow.txt" (
  net use !DRVLR! "\\%_SRV1%\!DRVMP!" /yes 1>> nul 2>&1
  IF ERRORLEVEL 1 (
   for %%D in (Z Y X W V U T S R Q P O N M L K J I H G F E D C) do CD %%D: 1>> nul 2>&1 & if errorlevel 1 set DRVLR=%%D:
   net use !DRVLR! "\\%_SRV1%\!DRVMP!" /yes 1>> nul 2>&1
  )
  echo Mapped Drive Letter !DRVLR! to \\%_SRV1%\!DRVMP!
 )
)

PHP sockets send auth email (gmail)

posted Mar 20, 2012 10:56 AM by Chris Franklin

functions

function logit($txt) {
 $log = fopen('/tmp/mail.txt','a+');;
 fwrite($log,$txt."\n");
 fclose($log);
}

function SendMail($ServerName, $Port, $ToEmail, $FromEmail, $Subject, $Body, $Header = '', $Username = '', $Password = '') {

 $smtp = fsockopen($ServerName, $Port);
 $InputBuffer = fgets($smtp, 1024);
 $GECode=220;
 if (substr($InputBuffer,0,3) != $GECode) {
  logit('Connect:'.$InputBuffer);
  fclose($smtp);
  return FALSE;
 }

 fputs($smtp, "HELO $ServerName\n");
 $InputBuffer = fgets($smtp, 1024);
 $GECode=250;
 if (substr($InputBuffer,0,3) != $GECode) {
  fclose($smtp);
  logit('HELO:'.$InputBuffer);
  return FALSE;
 }


 if ($Username != '') {
  fputs($smtp,"AUTH LOGIN\n");
  $smtpResponse = fgets($smtp, 1024);
  $GECode=250;
  if (substr($InputBuffer,0,3) != $GECode) {
   fclose($smtp);
   logit('AUTH'.$InputBuffer);
   return FALSE;
  }


  if ($Username != '') {
   fputs($smtp, base64_encode($Username)."\n");
   $smtpResponse = fgets($smtp, 1024);
   $GECode=250;
   if (substr($InputBuffer,0,3) != $GECode) {
    fclose($smtp);
    logit($InputBuffer);
    return FALSE;
   }
  }

  if ($Password != '') {
   fputs($smtp, base64_encode($Password)."\n");
   $smtpResponse = fgets($smtp, 1024);
   $GECode=250;
   if (substr($InputBuffer,0,3) != $GECode) {
    fclose($smtp);
    logit($InputBuffer);
    return FALSE;
   }
  }
 }


 fputs($smtp, "MAIL From:<$FromEmail>\n");
 $InputBuffer = fgets($smtp, 1024);
 $GECode=250;
 if (substr($InputBuffer,0,3) != $GECode) {
  fclose($smtp);
  logit($InputBuffer);
  return FALSE;
 }


 fputs($smtp, "RCPT To:<$ToEmail>\n");
 $InputBuffer = fgets($smtp, 1024);
 $GECode=250;
 if (substr($InputBuffer,0,3) != $GECode) {
  fclose($smtp);
  logit($InputBuffer);
  return FALSE;
 }

 fputs($smtp, "DATA\n");
 $InputBuffer = fgets($smtp, 1024);
 $GECode=354;
 if (substr($InputBuffer,0,3) != $GECode) {
  fclose($smtp);
  logit($InputBuffer);
  return FALSE;
 }


 fputs($smtp, "From: $FromEmail\n");
 fputs($smtp, "To: $ToEmail\n");
 if ($Header != '') {
  fputs($smtp, "$Header");
 }
 fputs($smtp, "Subject: $Subject\n\n");
 fputs($smtp, "$Body\r\n.\r\n");
 fputs($smtp, "QUIT\n");
 $InputBuffer = fgets($smtp, 1024);
 $GECode=250;
 if (substr($InputBuffer,0,3) != $GECode) {
  fclose($smtp);
  logit($InputBuffer);
  return FALSE;
 }

 fclose($smtp);
 return TRUE;
}

Call

$server = 'ssl://smtp.gmail.com ';
$port = 465;
$to = 'bob@aol.com';
$from = 'norely@somewhere.com';
$subject = 'Hi Mom';
$message = 'blah blah blah';

SendMail($server,$port,$to,$from,$subject,$message,$headers,$auth_username,$auth_password);

Bash String matching CASE SWITCH

posted Mar 5, 2012 10:58 AM by Chris Franklin   [ updated Mar 5, 2012 11:47 AM ]

Example

String="1 2 3 4 5"
case $String in
  "1 2 3 4 5") echo "matches exactly";;
  "1 2 3"*) echo "matches at the start";;
  *"3 4 5") echo "matches at the end";;
  *"2 3 4"*) echo "matches in the middle";;
  *) echo "No Matches";;
esac

Delete IP (network) based installed printers - XP

posted Mar 17, 2011 11:05 AM by Chris Franklin


Script

wmic printer where "PortName LIKE 'IP_%%'" delete

Robocopy with delete-before (example)

posted Jan 3, 2011 9:45 PM by Chris Franklin   [ updated Jan 3, 2011 10:00 PM ]

Simple backup example

::Path to robocopy
set RC="C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" 

::Source Path (location of files that need to be backed up)
set SP=M:\

::Destination Path (Where the backup lives)
set DT=\\Server\Backup

::Remove all the non-existing from the destination that do not exist on the source
%RC% /FFT %SP% %DT% /nocopy /PURGE /E

::Run mirror backup now
%RC% /FFT /MIR %SP% %DT%

Fixing DirectX on "Windows Fundamentals for Legacy PCs"

posted Dec 11, 2010 9:45 AM by Chris Franklin

If your like me and using WinFLP ("Windows Fundamentals for Legacy PCs") then you've probably notice that when you choose not to install IE , Media player, etc. That the DirectX that it installs is not complete and well basically for that it is does well nothing for you as far as gaming goes. Well heres a script that will fix that for you. And heres what you'll need to run it.

Another PC running Windows with the version of DX you want and still has the server service running. And next you'll need this script below (Your going to want to replace all "REMOTEPC" the with the name of your other PC).

Side note : I do prefer running WinFLP on ANY PC that needs XP or "higher". For if no other reason then it runs smoother, uses up way less resources (basic install with themes still running only uses ~70-80 MB of ram, and I've even gotten it down to 50 Mb and with no functional loss to the user). It's got a lot smaller base (after install it only uses about ~650 MB HD space). And as far as functionality goes it identical to WinXP SP2.

And again like I said I run this EVERY WHERE I "need" windows, regardless of how monster us the PC maybe !


Batch file

xcopy /y \\REMOTEPC\C$\windows\system32\ddraw.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ddrawex.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dxapi.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3d8.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3d8thk.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3d9.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3dim.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3dim700.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3drm.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3dxof.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\d3dpmesh.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dplay.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dplayx.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpmodemx.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpwsock.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpwsockx.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dplaysvr.exe c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnsvr.exe c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnet.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnlobby.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnaddr.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpvoice.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpvsetup.exe c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpvvox.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpvacm.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnhpast.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpnhupnp.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dpserial.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dinput.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dinput8.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dimap.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\diactfrm.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\joy.cpl c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\gcdef.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dsound.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dsound3d.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dswave.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dsdmo.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dsdmoprp.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmusic.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmband.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmcompos.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmime.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmloader.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmstyle.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmsynth.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dmscript.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dx7vb.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dx8vb.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dxdiagn.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mfc40.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mfc42.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\wsock32.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\amstream.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\devenum.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\dxmasf.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mciqtz32.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\msdmo.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\encapi.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qasf.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qcap.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qdv.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qdvd.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qedit.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\qedwipes.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\quartz.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\strmdll.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\iac25_32.ax c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir41_32.ax c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir41_qc.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir41_qcx.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir50_32.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir50_qc.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ir50_qcx.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ivfsrc.ax c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mswebdvd.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ks.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ksproxy.ax c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ksuser.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\stream.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mspclock.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mspqm.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mskssrv.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\swenum.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mstee.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ipsink.ax c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\mpe.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\streamip.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\msvidctl.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\slip.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\nabtsfec.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\ccdecode.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\msyuv.dll c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\wstcodec.sys c:\windows\system32\
xcopy /y \\REMOTEPC\C$\windows\system32\wstdecod.dll c:\windows\system32\

mkvmerge strip out unwanted tracks (batch)

posted Nov 20, 2010 6:47 AM by Chris Franklin   [ updated Nov 20, 2010 7:14 AM ]

Heres what I was trying to do
  1. strip out all non english audio tracks
  2. strip out all subtitles except for signs/songs/opening/etc
  3. name each audio track by it's type (in this case "AC3, 5.1 channels")
  4. name the video track by the files title wiht out the name of the show (aka 01x01 - bob instead of Air - 01x01 - bob)
  5. remove all extra attachments to the files
To do this I mixed up a simple custom mkvmerge script and a find command. In mkvmerge script I needed to look at the given file name and create a title for ther video track from that. To do that I this.

Create title

title=`echo "${file}" | sed -e 's/Air\ \-\ //g' | sed -e 's/\.mkv//g' | sed -e 's/\.\///g'`

All that really amounts to taking something with the file name of 

File name

./Air - 01x01 - bob.mkv
and turning it into

Title Name

01x01 - bob

Next I needed to keep only the audio & subtitle tracks I wanted. which ended up looking like this

Keeping only selected tracks

-a 2 -s 4 -M 
Broken down "-a 2" means keep track #2 and treat it as a audio track. It does NOT mean  keep audio track #2. mkvtools treats everything like a generic track regardless of that type of track it is. So you always care about the track NUMBER and nothing else. 

The "-s 4" means keep track #4 and treat it like a subtitle.
The "-M" means keep NO attachments (aka strip all attachments).

Now you might what to clean up the names of those tracks. To do that just use "--track-name " then the track number:Name_of_track  like this.

Name Tracks

--track-name 1:"${title}" --track-name 2:"AC3, 5.1 channels" --track-name 4:"Signs and Songs" 

And put all toghter here is my runme.sh script that will be called by find.

runme.sh

#!/bin/bash
file=$1
title=`echo "${file}" | sed -e 's/Air\ \-\ //g' | sed -e 's/\.mkv//g' | sed -e 's/\.\///g'`
echo $title
mkvmerge -a 2 -s 4 -M --track-name 1:"${title}" --track-name 2:"AC3, 5.1 channels" --track-name 4:"Signs and Songs" -o "${file}.mkv" "${file}"

And here is find command.

Find command used

find -iname "*.mkv"  ! -iname "*.mkv.mkv" -exec sh runme.sh '{}' \;

And in doing all this we went from this

Org info

File 'Air - 01x12 - Sora, Air.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AC3)
Track ID 3: audio (A_FLAC)
Track ID 4: subtitles (S_TEXT/ASS)
Track ID 5: subtitles (S_TEXT/ASS)
Attachment ID 1: type 'application/x-truetype-font', size 157360 bytes, file name 'MTCORSVA.TTF'
Attachment ID 2: type 'application/x-truetype-font', size 57336 bytes, file name 'RotisWTF.ttf'
Attachment ID 3: type 'application/x-truetype-font', size 842964 bytes, file name 'timesbd.ttf'
Attachment ID 4: type 'application/x-truetype-font', size 751104 bytes, file name 'arialbd.ttf'
Attachment ID 5: type 'application/x-truetype-font', size 56924 bytes, file name 'AVGARDNEclipse.ttf'
Attachment ID 6: type 'application/x-truetype-font', size 32364 bytes, file name 'BellGothicStd-Black.otf'
Attachment ID 7: type 'application/x-truetype-font', size 5178844 bytes, file name 'kaiu.ttf'
Attachment ID 8: type 'application/x-truetype-font', size 848720 bytes, file name 'calibrib.ttf'
Attachment ID 9: type 'application/x-truetype-font', size 172732 bytes, file name 'segoepr.ttf'
Attachment ID 10: type 'application/x-truetype-font', size 172092 bytes, file name 'segoeprb.ttf'
Chapters: 6 entries
to this

New Info

File 'Air - 01x12 - Sora, Air.mkv.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AC3)
Track ID 3: subtitles (S_TEXT/ASS)
Chapters: 6 entries

Which not only reduced the required space from 784 to 478 MB. But also cleaned up the track titles, made Eng of the only lang (thus the default). 

Proxy.pac + UNC/File path

posted Nov 17, 2010 11:29 AM by Chris Franklin

FireFox

file://///hs/netlogon/proxy.pac

IE

file:////hs/netlogon/proxy.pac

Windows Batch file, find drive letter from label

posted Apr 7, 2010 8:41 AM by Chris Franklin   [ updated Mar 2, 2011 7:39 AM ]

This script will allows you look for a drive's assigned letter based on it's label.  And the thing you need to do is make sure you change the "Backups" text to the text that is your devices label.


Code

set DriveLabel=Backups

for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
 for /f "tokens=6 delims= " %%i in ('vol %%a: ^|find "drive"') do (
  echo %%i | find /i "%DriveLabel%" > nul
  if not errorlevel 1 set DriveLetter=%%a
 )
)

Convert IP To Country database into per country ip ranges files

posted Jan 5, 2010 1:48 PM by Chris Franklin

The great people over at http://software77.net/cgi-bin/ip-country/geo-ip.pl have wonderFREE geolocation database that updated about every 24 hrs. But for me there way one problem the database used long or DOUBLE for storing the ipaddress. And we’ll the application I need / wanted to use required that I use standard “dotted” ipaddresses and ranges. So I can up with this little script. It will conver that 1 large database into seperate files, 1 for each country with all the ipaddresses / ranges for that country in that fie (go figure).

To use this script simply do the fallowing in order

  1. down the database from http://software77.net/cgi-bin/ip-country/geo-ip.pl. 
  2. unzip or ungzip the the file 
  3. make sure everything has write and read permissions
  4. create the file IpToCountry_2_Countries.php
  5. paste in the below code
  6. run the script php IpToCountry_2_Countries.php
mkdir('IpToCountry/');
$handle = fopen("IpToCountry.csv", "r");
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
 if ($row[0][0] != '#' and trim($row[0]) != '') {
  if (!$handles[$row[5]]) {
   $handles[$row[5]] = fopen("IpToCountry/".$row[5], "a");
  }
  fwrite($handles[$row[5]], long2ip($row[0]).'-'.long2ip($row[1])."\n");
 }
}

1-10 of 13