<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Quan Tran</title>
	<atom:link href="https://qtran.info/feed/" rel="self" type="application/rss+xml" />
	<link>https://qtran.info</link>
	<description></description>
	<lastBuildDate>Sat, 20 Oct 2018 14:12:34 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://qtran.info/wp-content/uploads/2018/10/cropped-logo-2-32x32.jpg</url>
	<title>Quan Tran</title>
	<link>https://qtran.info</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Powershell WOL script</title>
		<link>https://qtran.info/powershell-wol-script/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Sat, 20 Oct 2018 14:12:34 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script to wake a computer via network using Windows Powershell. # Script to wake up a computer over network. param( [string]$mac = &#8217;00:00:00:00:00:00&#8242; #address of the network card (MAC address) ) #checks the syntax of MAC address if (!($mac -like &#8220;*:*:*:*:*:*&#8221;) -or ($mac -like &#8220;*-*-*-*-*-*&#8221;)){ write-error &#8220;mac address not in correct format&#8221; break } #build magic package http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet $string=@($mac.split(&#8220;:&#8221;&#8221;-&#8220;) &#124; foreach {$_.insert(0,&#8221;0x&#8221;)}) $target = [byte[]]($string[0], $string[1], $string[2], $string[3], $string[4], $string[5]) # The magic packet is a broadcast frame containing anywhere [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script to wake a computer via network using Windows Powershell.</p>
<blockquote><p># Script to wake up a computer over network.</p>
<p>param(<br />
[string]$mac = &#8217;00:00:00:00:00:00&#8242; #address of the network card (MAC address)<br />
)</p>
<p>#checks the syntax of MAC address<br />
if (!($mac -like &#8220;*:*:*:*:*:*&#8221;) -or ($mac -like &#8220;*-*-*-*-*-*&#8221;)){<br />
write-error &#8220;mac address not in correct format&#8221;<br />
break<br />
}</p>
<p>#build magic package http://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet<br />
$string=@($mac.split(&#8220;:&#8221;&#8221;-&#8220;) | foreach {$_.insert(0,&#8221;0x&#8221;)})<br />
$target = [byte[]]($string[0], $string[1], $string[2], $string[3], $string[4], $string[5])<br />
# The magic packet is a broadcast frame containing anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal)<br />
$packet = [byte[]](,0xFF * 102)<br />
# followed by sixteen repetitions of the target computer&#8217;s 48-bit MAC address, for a total of 102 bytes.<br />
6..101 |% { $packet[$_] = $target[($_%6)]}</p>
<p># .NET framework lib para sockets<br />
$UDPclient = new-Object System.Net.Sockets.UdpClient<br />
$UDPclient.Connect(([System.Net.IPAddress]::Broadcast),4000)<br />
$UDPclient.Send($packet, $packet.Length) | out-null</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Batch FOR loop and variable modifiers</title>
		<link>https://qtran.info/batch-for-loop-and-variable-modifiers/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Fri, 19 Oct 2018 20:18:11 +0000</pubDate>
				<category><![CDATA[Others]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Write a FOR loop such as below @echo off for /R &#8220;C:\Users\Admin\Desktop&#8221; %%I in (*.*) do ( echo %%~nI ) pause To modifier the variable I, use the following %~I Expands %I which removes any surrounding quotation marks (&#8220;&#8221;). %~fI Expands %I to a fully qualified path name. %~dI Expands %I to a drive letter only. %~pI Expands %I to a path only. %~nI Expands %I to a file name only. %~xI Expands %I to a file extension only. %~sI [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Write a FOR loop such as below</p>
<blockquote><p>@echo off<br />
for /R &#8220;C:\Users\Admin\Desktop&#8221; %%I in (*.*) do (<br />
echo %%~nI<br />
)<br />
pause</p></blockquote>
<p>To modifier the variable I, use the following</p>
<blockquote><p>%~I Expands %I which removes any surrounding quotation marks (&#8220;&#8221;).<br />
%~fI Expands %I to a fully qualified path name.<br />
%~dI Expands %I to a drive letter only.<br />
%~pI Expands %I to a path only.<br />
%~nI Expands %I to a file name only.<br />
%~xI Expands %I to a file extension only.<br />
%~sI Expands path to contain short names only.<br />
%~aI Expands %I to the file attributes of file.<br />
%~tI Expands %I to the date and time of file.<br />
%~zI Expands %I to the size of file.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Paste from Clipboard</title>
		<link>https://qtran.info/paste-from-clipboard/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:44:58 +0000</pubDate>
				<category><![CDATA[VBScript]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script will paste from clipboard to a file. Set objHTML = CreateObject(&#8220;htmlfile&#8221;) ClipboardText = objHTML.ParentWindow.ClipboardData.GetData(&#8220;text&#8221;) path = &#8220;C:/temp_t.txt&#8221; Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;) Set objFile = objFSO.OpenTextFile(path, 2, true) objFile.WriteLine ClipboardText objFile.Close]]></description>
										<content:encoded><![CDATA[<p>Script will paste from clipboard to a file.</p>
<blockquote><p>Set objHTML = CreateObject(&#8220;htmlfile&#8221;)<br />
ClipboardText = objHTML.ParentWindow.ClipboardData.GetData(&#8220;text&#8221;)<br />
path = &#8220;C:/temp_t.txt&#8221;<br />
Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
Set objFile = objFSO.OpenTextFile(path, 2, true)<br />
objFile.WriteLine ClipboardText<br />
objFile.Close</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Automate RSA SecurID token authentication</title>
		<link>https://qtran.info/automate-rsa-securid-token-authentication/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:42:49 +0000</pubDate>
				<category><![CDATA[VBScript]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script to automatic RSA SecurID token authentication by opening up RSA, send the PIN, then copy the token and close RSA. &#8216; Opens RSA SecurID application, sends out the PIN code and then closes it &#8216; Kill current open process myProcess=&#8221;SecurID.exe&#8221; Set Processes = GetObject(&#8220;winmgmts:&#8221;).InstancesOf(&#8220;Win32_Process&#8221;) For Each Process In Processes If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then Process.Terminate() End If Next &#8216; Main code SecApp = &#8220;C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe&#8221; Set SecObj = CreateObject(&#8220;WScript.Shell&#8221;) SecObj.Exec(SecApp) WScript.Sleep 1000 MySendKeys(&#8220;12345&#8221;) [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script to automatic RSA SecurID token authentication by opening up RSA, send the PIN, then copy the token and close RSA.</p>
<blockquote><p>&#8216; Opens RSA SecurID application, sends out the PIN code and then closes it</p>
<p>&#8216; Kill current open process<br />
myProcess=&#8221;SecurID.exe&#8221;<br />
Set Processes = GetObject(&#8220;winmgmts:&#8221;).InstancesOf(&#8220;Win32_Process&#8221;)<br />
For Each Process In Processes<br />
If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then<br />
Process.Terminate()<br />
End If<br />
Next</p>
<p>&#8216; Main code<br />
SecApp = &#8220;C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe&#8221;<br />
Set SecObj = CreateObject(&#8220;WScript.Shell&#8221;)<br />
SecObj.Exec(SecApp)<br />
WScript.Sleep 1000<br />
MySendKeys(&#8220;12345&#8221;) &#8216;send PIN<br />
MySendKeys(&#8220;{ENTER}&#8221;)<br />
MySendKeys(&#8220;^{c}&#8221;) &#8216;send CTRL+C<br />
MySendKeys(&#8220;%{F4}&#8221;)</p>
<p>&#8216; Function to sendkeys<br />
Function MySendKeys(keys)<br />
SecObj.AppActivate(SecApp)<br />
WScript.Sleep 250<br />
SecObj.SendKeys(keys)<br />
End Function</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Terminate a running process</title>
		<link>https://qtran.info/terminate-an-open-process/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:35:44 +0000</pubDate>
				<category><![CDATA[VBScript]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script to terminal an open processes. &#8216; Kill current open process myProcess=&#8221;Something.exe&#8221; Set Processes = GetObject(&#8220;winmgmts:&#8221;).InstancesOf(&#8220;Win32_Process&#8221;) For Each Process In Processes If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then Process.Terminate() End If Next]]></description>
										<content:encoded><![CDATA[<p>Script to terminal an open processes.</p>
<blockquote><p>&#8216; Kill current open process<br />
myProcess=&#8221;Something.exe&#8221;<br />
Set Processes = GetObject(&#8220;winmgmts:&#8221;).InstancesOf(&#8220;Win32_Process&#8221;)<br />
For Each Process In Processes<br />
If StrComp(Process.Name, myProcess, vbTextCompare) = 0 Then<br />
Process.Terminate()<br />
End If<br />
Next</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>POST Json message to server</title>
		<link>https://qtran.info/post-json-message-to-server/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:28:45 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Send a POST to a Json server #!/bin/bash BOT_SERVICE=&#8221;http://bots.json.com&#8221; message=$(cat &#60;&#60;EOF { &#8220;to&#8221;:&#8221;test@test.com&#8221;, &#8220;from&#8221;:&#8221;test@test.com&#8221;, &#8220;html&#8221;:&#8221;&#60;font color=&#8217;red&#8217;&#62;Am a bot.&#60;/font&#62;&#8221; } EOF ) curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE Can also read in a file and format that as the message #!/bin/bash bot_input=&#8221;bot_input.txt&#8221; BOT_SERVICE=&#8221;http://bots.json.com&#8221; html_input=$(&#60;$bot_input) message=$(cat &#60;&#60;EOF { &#8220;to&#8221;:&#8221;test@test.com&#8221;, &#8220;from&#8221;:&#8221;test@test.com&#8221;, &#8220;html&#8221;:&#8221;$html_input&#8221; } EOF ) curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE]]></description>
										<content:encoded><![CDATA[<p>Send a POST to a Json server</p>
<blockquote><p>#!/bin/bash<br />
BOT_SERVICE=&#8221;http://bots.json.com&#8221;</p>
<p>message=$(cat &lt;&lt;EOF<br />
{<br />
&#8220;to&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;from&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;html&#8221;:&#8221;&lt;font color=&#8217;red&#8217;&gt;Am a bot.&lt;/font&gt;&#8221;<br />
}<br />
EOF<br />
)<br />
curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE</p></blockquote>
<p>Can also read in a file and format that as the message</p>
<blockquote><p>#!/bin/bash</p>
<p>bot_input=&#8221;bot_input.txt&#8221;<br />
BOT_SERVICE=&#8221;http://bots.json.com&#8221;</p>
<p>html_input=$(&lt;$bot_input)</p>
<p>message=$(cat &lt;&lt;EOF<br />
{<br />
&#8220;to&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;from&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;html&#8221;:&#8221;$html_input&#8221;<br />
}<br />
EOF<br />
)<br />
curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SSH to multiple servers using Expect</title>
		<link>https://qtran.info/ssh-to-multiple-servers-using-expect/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:24:50 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script will login to multiple servers and perform certain command automatically. Requires an input file of format HostName:IP:Pass #!/bin/bash # Require an input.txt file with the format of CLLI:IP:Pass # This scirpt will add the RSA key for lss user if [ -e &#8220;input.txt&#8221; ]; then while read i; do /usr/bin/expect &#60;(cat &#60;&#60; EOD set timeout 15 spawn ssh &#8220;user@$(echo $i &#124; cut -d: -f 2)&#8221; ####################### expect &#8220;yes/no&#8221; { send &#8220;yes\r&#8221; expect &#8220;Password:&#8221; { send {$(echo $i &#124; cut [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script will login to multiple servers and perform certain command automatically.</p>
<p>Requires an input file of format HostName:IP:Pass</p>
<blockquote><p>#!/bin/bash<br />
# Require an input.txt file with the format of CLLI:IP:Pass<br />
# This scirpt will add the RSA key for lss user</p>
<p>if [ -e &#8220;input.txt&#8221; ]; then<br />
while read i; do</p>
<p>/usr/bin/expect &lt;(cat &lt;&lt; EOD<br />
set timeout 15<br />
spawn ssh &#8220;user@$(echo $i | cut -d: -f 2)&#8221;<br />
#######################</p>
<p>expect &#8220;yes/no&#8221; {<br />
send &#8220;yes\r&#8221;<br />
expect &#8220;Password:&#8221; { send {$(echo $i | cut -d: -f 3)}; send \r }<br />
} &#8220;Password:&#8221; { send {$(echo $i | cut -d: -f 3)}; send \r }<br />
expect -re &#8220;day: $&#8221; { send &#8220;\r&#8221; }<br />
expect &#8220;:&#8221; { send &#8220;\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;ll\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;mkdir .ssh\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;cd .ssh\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;touch authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;chmod 700 authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;echo &#8216;ssh-rsa KEY&#8217; &gt;&gt; authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;cat authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;exit\r&#8221; }<br />
EOD<br />
)<br />
done &lt; input.txt<br />
fi</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Sendmail sample</title>
		<link>https://qtran.info/sendmail-sample/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:20:07 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Sendmail script passing in a file as message. File have filename format test.hostname.network #!/bin/bash mailserver=&#8217;test@test.com&#8217; for f in $* do m=$( echo $f &#124; cut -d. -f2 ) mail -s &#8220;XML file from $m&#8221; $mailserver &#60; $f done You execute the script as such ./sample_script.sh filename ./sample_script.sh test*                    # execute for all files begin with test in directory]]></description>
										<content:encoded><![CDATA[<p>Sendmail script passing in a file as message. File have filename format test.hostname.network</p>
<blockquote><p>#!/bin/bash</p>
<p>mailserver=&#8217;test@test.com&#8217;<br />
for f in $*<br />
do<br />
m=$( echo $f | cut -d. -f2 )<br />
mail -s &#8220;XML file from $m&#8221; $mailserver &lt; $f<br />
done</p></blockquote>
<p>You execute the script as such</p>
<blockquote><p>./sample_script.sh filename</p>
<p>./sample_script.sh test*                    # execute for all files begin with test in directory</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Download from multiple servers using SCP</title>
		<link>https://qtran.info/download-from-multiple-servers-using-scp/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:06:33 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script allow you to download from multiple servers using SCP protocol and sshpass to send password for authentication. Files will be stored in different directory with hostname. Requires an input file with format HostName:IP:Pass if [ -e &#8220;input.txt&#8221; ]; then while read i; do mkdir &#8220;$(echo $i &#124; cut -d: -f 1)&#8221; echo &#8220;$(echo $i &#124; cut -d: -f 3)&#8221; &#62; pass.txt sshpass -f &#8220;pass.txt&#8221; scp -o StrictHostkeyChecking=no user@&#8221;$(echo $i &#124; cut -d: -f 2)&#8221;:/tmp/*sample &#8220;./$(echo $i&#124;cut -d: -f 1)&#8221; [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script allow you to download from multiple servers using SCP protocol and sshpass to send password for authentication. Files will be stored in different directory with hostname.</p>
<p>Requires an input file with format HostName:IP:Pass</p>
<blockquote><p>if [ -e &#8220;input.txt&#8221; ]; then<br />
while read i; do<br />
mkdir &#8220;$(echo $i | cut -d: -f 1)&#8221;<br />
echo &#8220;$(echo $i | cut -d: -f 3)&#8221; &gt; pass.txt<br />
sshpass -f &#8220;pass.txt&#8221; scp -o StrictHostkeyChecking=no user@&#8221;$(echo $i | cut -d: -f 2)&#8221;:/tmp/*sample &#8220;./$(echo $i|cut -d: -f 1)&#8221;<br />
done &lt; input.txt<br />
fi</p>
<p>rm pass.txt</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
