I used this script to check the last redirect url:
set http = CreateObject("Chilkat_9_5_0.Http")
http.FollowRedirects = 0
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.QuickGetObj(link)
If (http.LastMethodSuccess = 0) Then
wscript.echo http.LastErrorText
WScript.Quit
End If
status = resp.StatusCode
wscript.echo "HTTP Response Status: " & status
wscript.echo "Redirect URL >>>: " & http.FinalRedirectUrl
nextUrl = http.WasRedirected
loopCount = 0
Do While (status = 302 OR status = 301)
wscript.echo "HTTP Response Status: " & status
wscript.echo "Redirect URL >>>: " & http.FinalRedirectUrl
nextUrl = http.FinalRedirectUrl
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.QuickGetObj(nextUrl)
If (http.LastMethodSuccess = 0) Then
wscript.echo http.LastErrorText
WScript.Quit
End If
status = resp.StatusCode
wscript.echo "HTTP Response Status: " & status
' For safety, prevent infinite loops by
' keeping a loopCount and only allows following a max
' of 10 redirects:
loopCount = loopCount + 1
If (loopCount > 10) Then
wscript.echo "Too many redirects."
WScript.Quit
End If
Loop
This code prints the 301 status code correctly, but it doesn't print the http.FinalRedirectURL (it's blank).
I also tried with the url https://www.businessonline.it/articoli/guida-al-nuovo-regime-forfettario-2016-e-2017.html
The output is:
Link: https://www.businessonline.it/articoli/guida-al-nuovo-regime-forfettario-2016-e-2017.html
HTTP Response Status: 301
Redirect URL >>>:
HTTP Response Status: 301
Redirect URL >>>:
ChilkatLog:
QuickGetObj:
DllDate: Oct 28 2019
ChilkatVersion: 9.5.0.80
UnlockPrefix: BRKEVN.XXXXXXXXXXX
Architecture: Little Endian; 32-bit
Language: ActiveX
VerboseLogging: 0
Component successfully unlocked using purchased unlock code.
url:
verb: GET
quickRequestDb:
url:
getHttpConnectionByUrl:
urlObject_loadUrl:
No domain in URL
url:
--urlObject_loadUrl
--getHttpConnectionByUrl
--quickRequestDb
Failed.
--QuickGetObj
--ChilkatLog
I used both chilkat 9.5.0.70 and 9.5.0.80.
If I set FollowRedirects to 1, the first StatusCode is "200" and I can't get the url.
Can you help me?
Thank's
Thanks Lorenzo,
The problem had to do with QuickGetObj and QuickGet. The QuickGetStr method worked fine for the WasRedirected and FinalRedirectUrl properties.
Here's a new 32-bit ActiveX build with the fix:
32-bit: https://chilkatdownload.com/prerelease/chilkatax-9.5.0-win32-1630.zip
Can any one tell me why I am getting an error message with this code:
I am trying to recycle app pools with a wmi script
Line that errors is "set objWMIService ..."
Error message is "0x8004100E"
RecycleAppPools("myComputerName")
Sub RecycleAppPools(strComputer)
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}//" _
& strComputer & "/root/MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery _
("Select * From IIsApplicationPool ")
For Each objItem in colItems
objItem.Recycle
Next
End Sub
VirtualBox is able to compact (reduce the size) of .vdi images but it is not possible with .vmdk disk images. But we can compact .vmdk files if we:
detach
convert to .vdi
compact
convert back to .vmdk
attach again to the original vitual machine
So I tried to shrink my VirtualBox image with this script:
#/bin/bash
VM_PATH=~/VirtualBox\ VMs
cd "$VM_PATH"
VM="$(ls ffnord-example_gc-gw0_* -d -1|head -n 1)"
cd "$VM"
VM_VDMK_NAME="$(ls *.vmdk -1|head -n 1)"
VM_NAME="$VM_PATH/$VM/$VM_VDMK_NAME"
echo reducing size of "$VM_NAME"
ls -lah "$VM_NAME"
set -x
vboxmanage showvminfo "${VM}"
vboxmanage storageattach "${VM}" --storagectl SATA --port 0 --device 0 --type hdd --medium none
vboxmanage clonehd --format vdi "${VM_NAME}" /tmp/VM-disk.vdi
vboxmanage closemedium disk "${VM_NAME}" --delete
vboxmanage modifyhd /tmp/VM-disk.vdi --compact
vboxmanage clonehd --format vmdk /tmp/VM-disk.vdi "${VM_NAME}"
vboxmanage closemedium disk /tmp/VM-disk.vdi --delete
vboxmanage storageattach "${VM}" --storagectl SATA --port 0 --device 0 --type hdd --medium 4/VMs/VM-disk1.vmdk
I adapted this script from crysol but it seems this is not working on Ubuntu? The first vboxmanage storageattach starts with an error right away:
VBoxManage: error: Could not find a controller named 'SATA'
If I try "SATA Controller" instead:
vboxmanage storageattach "${VM}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium none
I get this error:
VBoxManage: error: No storage device attached to device slot 0 on port 0 of controller 'SATA Controller'
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "DetachDevice(Bstr(pszCtl).raw(), port, device)" at line 381 of file VBoxManageStorageController.cpp
If I comment out those vboxmanage storageattach lines, the script works fine, but the resulting VM is the same size as before and it doesn't boot anymore.
This is the output of vboxmanage showvminfo "${VM}"
I found a solution:
First inside the VM fill all free space with zeros:
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
In your Host, install vmware-vdiskmanager from the VMware Knowledge Base:
cd /tmp/
wget http://kb.vmware.com/selfservice/viewAttachment.do?attachID=1023856-vdiskmanager-linux.7.0.1.zip&documentID=1023856
unp 1023856-vdiskmanager-linux-7.0.1.zip
mv 1023856-vmware-vdiskmanager-linux.7.0.1 /usr/bin/vmware-vdiskmanager
chmod +x /usr/bin/vmware-vdiskmanager
Take care, that you have enough free disk-space before you start, you need the MV grows to double size during the process.
Then compress it with:
/usr/bin/vmware-vdiskmanager -k ~/VirtualBox\ VMs/<virtual disk.vmdk>
Source
I didn't need to install VMWare nor convert back to VMDK so I used
https://scotch.io/tutorials/how-to-create-a-vagrant-base-box-from-an-existing-one#toc-make-the-box-as-small-as-possible
Inside the host:
sudo yum clean all
sudo dd if=/dev/zero of=/EMPTY bs=1M
sudo rm -f /EMPTY
cat /dev/null > ~/.bash_history && history -c && exit
Then after the guest is shut down:
$ vboxmanage clonehd --format vdi centos-7-1-1.x86_64.vmdk newdisk.vdi
$ ls -lh
-rwx------+ 1 Chloe None 39G Mar 26 14:52 centos-7-1-1.x86_64.vmdk
-rwx------+ 1 Chloe None 22G Mar 26 15:01 newdisk.vdi
It also allows compaction later
$ vboxmanage modifyhd newdisk.vdi --compact
Inside VirtualBox GUI, I selected 'Choose Virtual Hard Disk File' to select the new file.
I could not get rubo77s solution above vmware-vdiskmanager solution to work, I believe it has dependencies on vmware workstation or vmware player, neither of which I have, I did find the executable and it gave me errors.
I was able to solve this by using his zero command
cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill
then using virtualboxes export to .ova tool.
this will result in the ova stripping/compressing the zeroed space.
then you can re-import it.
FYI:
as vmware modernized their knowledge base the download link is not valid anymore.
After some searching I found the zip attached with this link https://kb.vmware.com/sfc/servlet.shepherd/version/download/068f4000009EgK0AAK
Which is included in the case
https://kb.vmware.com/s/article/1023856?lang=en_US&queryTerm=1023856
Also the binary was failing with a missing library in my Ubuntu but downloading
http://archive.ubuntu.com/ubuntu/pool/universe/o/openssl098/libssl0.9.8_0.9.8o-7ubuntu3.1_i386.deb and installing it was helping.
Basically this answer should just be a comment for Shrink a vmdk Virtualbox disk image by rubo77 - but my reputation is too low so here you go.
I got this oooold script which allows you to wipe out all the unnecessary data, inside of Windows on your partition. It's written in VBscript:
`REM This script is published under the BSD Licence
REM http://www.opensource.org/licenses/bsd-license.php
Option Explicit
Const sDefaultDir = "C:\"
Const sDefaultFilename = "overwrite.garbage"
Const lStartBlockSize = 32768
Call Main
Sub Main()
Dim sPath, sFilename
Dim oArgs, oFS, oDrive, oRegExp, oMatches
ShowStartMsg
Set oArgs = WScript.Arguments
Set oFS = CreateObject("Scripting.FileSystemObject")
If oArgs.Count = 1 Then
If oArgs(0) = "/?" Then
ShowHelp true
End If
End If
If oArgs.Count > 2 Then
ShowMsg "ERROR: Invalid command line parameters (too many parameters specified)", true, true
End If
If oArgs.Count > 0 Then
sPath = oFS.GetAbsolutePathName(oArgs(0))
Else
sPath = ""
End If
If oFS.FolderExists(sPath) Then
WScript.Echo "Checking folder " & Chr(34) & sPath & Chr(34) & ": OK"
If Right(sPath, 1) <> "\" Then
sPath = sPath & "\"
End If
Else
WScript.Echo "Checking folder " & Chr(34) & sPath & Chr(34) & ": FAILED"
sPath = sDefaultDir
WScript.Echo "INFO: Using default folder " & Chr(34) & sPath & Chr(34)
End If
If oArgs.Count = 2 Then
sFilename = oArgs(1)
If sFilename = "" Then
ShowMsg "ERROR: Filename must not be empty", true, true
End If
Else
sFilename = sDefaultFilename
WScript.Echo "INFO: Using default filename " & Chr(34) & sFilename & Chr(34)
End If
Set oRegExp = new RegExp
oRegExp.Pattern = "[\\\/\:\*\?\" & Chr(34) & "\<\>\|]"
Set oMatches = oRegExp.Execute(sFilename)
If oMatches.Count = 0 Then
WScript.Echo "Validating filename: OK"
Else
WScript.Echo "Validating filename: FAILED"
ShowMsg "ERROR: Filename must not contain the following characters:"_
& " \ / : * ? " & Chr(34) & " < > |", true, true
End If
If oFS.FileExists(sPath & sFilename) = False Then
WScript.Echo "Ensuring that file " & Chr(34) & sFilename & Chr(34) &_
" does not exist: OK"
Else
WScript.Echo "Ensuring that file " & Chr(34) & sFilename & Chr(34) &_
" does not exist: FAILED"
ShowMsg "ERROR: File " & Chr(34) & sPath & sFilename & Chr(34) & " already exists", true, true
End If
Set oDrive = oFS.GetDrive(oFS.GetDriveName(sPath))
If UCase(oDrive.FileSystem) = "NTFS" Then
WScript.Echo "Checking for NTFS: OK"
Else
WScript.Echo "Checking for NTFS: FAILED"
ShowMsg "ERROR: " & oDrive.FileSystem & " file system not supported", true, true
End If
Select Case oDrive.DriveType
Case 1, 2
WScript.Echo "Checking drive type: OK"
Case Else
WScript.Echo "Checking drive type: FAILED"
Select Case oDrive.DriveType
Case 3
ShowMsg "ERROR: Network drives are not supported", true, true
Case 4
ShowMsg "ERROR: CD-ROM drives are not supported", true, true
Case 5
ShowMsg "ERROR: RAM Disk drives are not supported", true, true
Case Else
ShowMsg "ERROR: Unkown drives are not supported", true, true
End Select
End Select
If oDrive.FreeSpace > 0 Then
WScript.Echo "Checking for free space: OK"
Else
WScript.Echo "Checking for free space: FAILED"
WScript.Echo "INFO: No free space available (no action required)"
ShowMsg "INFO: Exiting Overwrite Script...", false, true
End If
WScript.Echo "Creating garbage file " & Chr(34) & sPath & sFilename & Chr(34) & "..."
CreateGarbageFile sPath & sFilename, oFS
WScript.Echo "Garbage file successfully created!"
WScript.Echo "INFO: " & oDrive.AvailableSpace & " byte(s) remained which could not be overwritten"
WScript.Echo "Deleting garbage file..."
oFS.DeleteFile sPath & sFilename
WScript.Echo "Garbage file successfully deleted!"
WScript.Echo "Exiting Overwrite Script..."
WScript.Quit
End Sub
Sub CreateGarbageFile(sAbsFilename, oFS)
Dim bSngByteBlock
Dim sBlock
Dim oFile, oDrive
bSngByteBlock = false
Set oDrive = oFS.GetDrive(oFS.GetDriveName(sAbsFilename))
Set oFile = oFS.CreateTextFile(sAbsFilename, false, false)
sBlock = String(lStartBlockSize, 0)
On Error Resume Next
Do While oDrive.FreeSpace > 0
If oDrive.FreeSpace < lStartBlockSize Then
If bSngByteBlock = false Then
WScript.Echo "INFO: Falling back to single byte block"
bSngByteBlock = true
sBlock = String(1, 0)
End If
End If
oFile.Write sBlock
If Err.Number <> 0 Then
WScript.Echo "WARNING: Error " & Chr(34) & Err.Description & Chr(34) & " ("_
& Err.Number & ") occured while writing garbage file"
Exit Do
End If
Loop
On Error GoTo 0
oFile.Close
End Sub
Sub ShowStartMsg()
WScript.Echo "Overwrite Script 1.0 (2004-09-05)"
WScript.Echo "Copyright (C) 2004 Dennis Dietrich"
WScript.Echo "http://www.myblog.de/scotty"
WScript.Echo ""
WScript.Echo "WARNING: The script is experimental. Use it at your own risk!"
WScript.Echo "To cancel the execution of this script press CTRL + C"
WScript.Echo ""
End Sub
Sub ShowMsg(sMsg, bShowHelpHint, bExit)
WScript.Echo sMsg
If bShowHelpHint = True Then
WScript.Echo ""
WScript.Echo "Use " & Chr(34) & "CScript Overwrite.vbs /?" & Chr(34) & " to get help."
End If
If bExit = True Then
WScript.Quit
End If
End Sub
Sub ShowHelp(bExit)
WScript.Echo "Cleans free disk space from recoverable data by overwriting it with random"
WScript.Echo "information. For a higher level of security execute this script at least three"
WScript.Echo "times. Only NTFS partitions are supported."
WScript.Echo ""
WScript.Echo "CScript Overwrite.vbs [path] [filename]"
If bExit = True Then
WScript.Quit
End IF
End Sub`
(inspired by http://www.codeproject.com/KB/vbscript/overwrite_script.aspx)
Has anyone ran into this issue? When the script gets to the banner text the script just hangs.
I am using Net::Appliance::Session
Here is the error I get in debug. The rest of the script inserts code perfectly. I did test what I read about adding a # to the banner for each line. Same result.
banner login +
[ 4.092880] tr nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
[ 4.093124] du SEEN:
banner login +
[ 4.093304] tr nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
[ 4.305872] du SEEN:
Enter TEXT message. End with the character '+'
[ 4.306121] tr nope, doesn't (yet) match (?-xism:[\/a-zA-Z0-9._\[\]-]+ ?(?:\(config[^)]*\))? ?[#>] ?$)
We had an issue when accessing the device : 10.49.216.74
The reported error was : read timed-out at /usr/lib/perl5/site_perl/5.10.0/Net/CLI/Interact/Transport/Wrapper/Net_Telnet.pm line 35
Here is a snip of code.
my $session_obj = Net::Appliance::Session->new(
host => $ios_device_ip,
transport => 'Telnet',
personality => 'ios',
timeout => 60,
);
#interace
$session_obj->set_global_log_at('debug');
eval {
# try to login to the ios device, ignoring host check
$session_obj->connect(
username => $ios_username,
password => $ios_password,
#SHKC => 0
);
# get our running config
$version_info = $session_obj->begin_privileged;
$session_obj->cmd('conf t');
$session_obj->cmd('line con 0');
$session_obj->cmd('exec-character-bits 8');
$session_obj->cmd('international');
$session_obj->cmd('line vty 0 4');
$session_obj->cmd('exec-character-bits 8');
$session_obj->cmd('international');
$session_obj->cmd('line vty 5 15');
$session_obj->cmd('exec-character-bits 8');
$session_obj->cmd('international');
$session_obj->cmd('exit');
$session_obj->cmd('no banner login');
$session_obj->cmd('banner login +');
$session_obj->cmd('*************************************************************************');
$session_obj->cmd('* test *');
$session_obj->cmd('* *');
$session_obj->cmd('*************************************************************************');
$session_obj->cmd('+');
$session_obj->cmd('no banner MOTD');
$session_obj->cmd('banner motd +');
$session_obj->cmd('*************************************************************************');
$session_obj->cmd('* test *');
$session_obj->cmd('* *');
$session_obj->cmd('*************************************************************************');
$session_obj->cmd('+');
$session_obj->cmd('exit');
$session_obj->cmd('write memory');
$session_obj->end_privileged;
# close down our session
$session_obj->close;
};
If you look at the regexp that matches the prompt before sending a new command you'll see that it requires a specific string that closely matches user, privileged or config mode of a router.
When you send the banner login + command you get the Enter TEXT message. End with the character '+' followed by blank line from a router (instead of Router(config)# that your script expects. After a while it just times out since there is no match for the regexp.
The easiest solution is to try to send the whole banner in one command. Try concatenating your banner with a \r in one string and sending it as a one command that looks like (note the double quotes):
$session_obj->cmd("banner login + line1 \r line2 \r line3\r +");
Took way too long to figure this out... spaces are not your friend.
$session_obj->cmd("banner login + \rline1\rline2\rline3\r+");
Example with my orginal problem:
$session_obj->cmd('*************************************************************************\r* test *\r* *\r*************************************************************************');
I have a text file containing the results of a zone transfer & need to read each line & split it into an array to output a list of server names & IP addresses. However I'me having some problems splitting the data as my attempt at the whitespace delimiter doesn't seem to be doing what I want it to.
Sample input:
machine1.fqdn.com. 86400 IN A 192.168.1.10
machine2.fqdn.com. 86400 IN A 192.168.1.11
machine3.fqdn.com. 86400 IN A 192.168.1.12
machine4.fqdn.com. 86400 IN A 192.168.1.13
Script:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("I:\testHarvestIF.txt", ForReading)
Const ForReading = 1
Do Until objFile.AtEndOfStream
strNextLine = objFile.Readline
arrServiceList = Split(strNextLine," ",-1,1)
Wscript.Echo "Server name: " & arrServiceList(0) & vbCrLF & _
" - IP Address: " & arrServiceList(2)
Loop
objFile.Close
Current Output:
Server name: machine1.fqdn.com.
IP Address: IN A 192.168.1.10
Server name: machine2.fqdn.com.
IP Address: IN A 192.168.1.11
Server name: machine3.fqdn.com.
IP Address: IN A 192.168.1.12
Server name: machine4.fqdn.com.
IP Address: IN A 192.168.1.13
Desired output:
Server name: machine1.fqdn.com.
IP Address: 192.168.1.10
Server name: machine2.fqdn.com.
IP Address: 192.168.1.11
Server name: machine3.fqdn.com.
IP Address: 192.168.1.12
Server name: machine4.fqdn.com.
IP Address: 192.168.1.13
Is there some way I could use a regular expresion to use any length of whitespace as a delimiter? E.g.
arrServiceList = Split(strNextLine,"^\s+",-1,1)
Thanks in advance for any assistance you can offer.
Regards,
RB
This might not work, depending on the format of your data, but you could try replacing the extra whitespace with a single space character before calling Split:
Dim re : Set re = New RegExp
re.Global = True
re.Pattern = "\s+"
Do Until objFile.AtEndOfStream
strNextLine = re.Replace(objFile.Readline, " ")
arrServiceList = Split(strNextLine," ",-1,1)
Wscript.Echo "Server name: " & arrServiceList(0) & vbCrLF & _
" - IP Address: " & arrServiceList(4)
Loop
Use the RegExp object (MSDN) to match the required string instead of spliting the string:
set regex = new RegExp
regexp.pattern = "^.*? "
set serverName = regex.execute(inputText).value
regex.pattern = " .*?$"
set ipAddress = regex.execute(inputText).value