I'm trying to realize a little script in Autoit that retrieves all IPs used by Facebook servers (query "-i origin AS32934" to whois.radb.net, as developer page says), but I don't understand why WhoIs servers are not responding to my queries.
This is the script:
Local $host = "whois.radb.net", $query = "-i origin AS32934"
If Ping($host) Then
$ws = DllOpen("ws2_32.dll")
TCPStartup()
$ip = TCPNameToIP($host)
If #error Then _err("TCPNameToIP", #error)
Global $socket = TCPConnect($ip, 43)
If #error Then _err("TCPConnect", #error)
TCPSend($socket, $query)
If #error Then _err("TCPSend", #error, 1)
Local $text = "", $t = TimerInit(), $counter = 0
While 1
$recv = TCPRecv($socket, 2048)
If #error And #error <> -1 Then
$aRet = DllCall($ws, "int", "WSAGetLastError")
MsgBox(16,"ERROR", "Function: TCPRecv" & #CRLF & "Last data received: " & $recv & #CRLF & "Winsock error: " & $aRet[0] & #CRLF & "Loop executed " & $counter & " times")
ExitLoop
EndIf
$text &= $recv
$counter += 1
If TimerDiff($t) > 4999 Then ExitLoop
WEnd
If $text = "" Then
MsgBox(48, "RESULT", "EMPTY" & #CRLF & "Loop executed " & $counter & " times")
Else
MsgBox(0, "RESULT", $text)
EndIf
TCPCloseSocket($socket)
TCPShutdown()
Else
_err("Ping", #error, 0)
EndIf
Func _err($func, $err, $opt = 2)
MsgBox(16, "ERROR", "Function: " & $func & #CRLF & "Error: " & $err)
If $opt = 1 Then TCPCloseSocket($socket)
If $opt > 0 Then TCPShutdown()
Exit
EndFunc
The output is always "RESULT:EMPTY".
I've tried to query other WhoIs services with various queries (for example whois.verisign-grs.com with "=facebook.com") but I get no response.
It's not a problem about my network, because I've tried a Nirsoft WhoIs tool ad it works.
I've downloaded a sniffer and this is the output when I start my script:
==================================================
Protocol : TCP
Local Address : 192.168.1.101
Remote Address : 198.108.0.18
Local Port : 23509
Remote Port : 43
Remote Host : whois.radb.net
Service Name : nicname
Packets : 5 {5 ; 0}
Data Size : 17 Bytes {17 ; 0}
Total Size : 274 Bytes {217 ; 57}
Data Speed : 0.0 KB/Sec
Capture Time : 07/07/2014 15:18:37:313
Last Packet Time : 07/07/2014 15:18:45:837
Duration : 00:00:08.523
==================================================
Content:
-i origin AS32934
It seems the packet is sent but no packet is received.
I just found out the solution: adding a #crlf at the end of TCPSend() request
$query = "-i origin AS32934" & #crlf
Related
Instead of the MsgBox i want the script to read a .txt file and write to the end of each line the result of a variable, in my case is $FileSize
Here is the code for autoit script
#include <MsgBoxConstants.au3>
#include <File.au3>
Test()
Func Test()
For $i = 1 to _FileCountLines(#TempDir & "\myfiles.txt")
$mread = FileReadLine(#TempDir & "\myfiles.txt", $i)
Local $FileSize = FileGetSize($mread)
MsgBox($MB_SYSTEMMODAL, "", ByteSuffix($FileSize)) ;this is just a test
Next
EndFunc ;==>Example
Func ByteSuffix($Bytes)
Local $Index = 0, $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']
While $Bytes > 1023
$Index += 1
$Bytes /= 1024
WEnd
Return Round($Bytes) & $aArray[$Index]
EndFunc
Here is the content of .txt file
C:\Users\G-PC\Documents\setup.exe
C:\Users\G-PC\Documents\config.ini
C:\Users\G-PC\Documents\image001.jpg
C:\Users\G-PC\Documents\image002.jpg
C:\Users\G-PC\Documents\image003.jpg
I want the following result
C:\Users\G-PC\Documents\setup.exe [SIZE FOR THIS]
C:\Users\G-PC\Documents\config.ini [SIZE FOR THIS]
C:\Users\G-PC\Documents\image001.jpg [SIZE FOR THIS]
C:\Users\G-PC\Documents\image002.jpg [SIZE FOR THIS]
C:\Users\G-PC\Documents\image003.jpg [SIZE FOR THIS]
There is a size limit for both string variables and arrays, so you have to process one line at a time when working with big files. This uses a temporary file for output instead of keeping all the information in memory. You can rename (overwriting the original file) the temporary file to the original file name at the end.
Func Test()
Local $InFile = FileOpen(#TempDir & "\myfiles.txt", $FO_READ)
Local $OutFile = FileOpen(#TempDir & "\myfiles.tmp", $FO_OVERWRITE)
While True
$File = FileReadLine($InFile)
If #error = -1 Then Return ; no more lines to process
FileWrite($OutFile, $File & " [" & ByteSuffix(FileGetSize($File)) & "]" & #CRLF)
WEnd
EndFunc ;==>Test
$sResult = Test()
ConsoleWrite('SIZE LIST' & #CRLF & $sResult)
Func Test()
Local $FileSize, $sReturn = ''
For $i = 1 to _FileCountLines(#TempDir & "\myfiles.txt")
$mread = FileReadLine(#TempDir & "\myfiles.txt", $i)
$FileSize = FileGetSize($mread)
; MsgBox($MB_SYSTEMMODAL, "", ByteSuffix($FileSize)) ;this is just a test
$sReturn &= $mread & " [" & ByteSuffix($FileSize) & "]" & #CRLF
Next
Return $sReturn
EndFunc ;==>Test
But a better way instead of reading the text file line by line is the using of _FileReadToArray. Than you can iterate through the array with text lines.
Using line number parameter for FileReadLine in a loop resets
the file pointer to the start and scans up to the line number which slows
down the loop as line count increases. Omit that parameter.
Use a file handle so you do not keep on opening and closing
the file with each line read in the loop.
#include <MsgBoxConstants.au3>
#include <File.au3>
$sResult = Test()
MsgBox(0, #ScriptName, $sResult)
Func Test()
Local $iFileSize, $hFile, $sFilePath, $sResult
; Open a file handle to read.
$hFile = FileOpen(#TempDir & "\myfiles.txt")
If $hFile = -1 Then
MsgBox(0x30, #ScriptName, 'Unable to open file to read.')
Exit 1
EndIf
While 1
; Read and let AutoIt handle line count.
$sFilePath = FileReadLine($hFile)
If #error Then ExitLoop
$iFileSize = FileGetSize($sFilePath)
If #error Then ContinueLoop
$sResult &= StringFormat('%s %s\r\n', $sFilePath, ByteSuffix($iFileSize))
WEnd
FileClose($hFile)
Return $sResult
EndFunc
Func ByteSuffix($Bytes)
Local $Index = 0
Local $aArray = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']
While $Bytes > 1023
$Index += 1
$Bytes /= 1024
WEnd
Return Round($Bytes) & $aArray[$Index]
EndFunc
I have an AutoIt script that works, mostly. Reads a file, writes out what I want, but it does not preserve the original newline character. If I read a UNIX format file (LF only), it will write out a Windows format file (CR and LF).
Short of switching to something more robust, like Python, how do I solve this in AutoIt?
Opt("MustDeclareVars", 1) ;0 = no, 1 = require pre-declare
#include <File.au3>
#include <Array.au3>
Local $gInPath = $CmdLine[1]
Local $NumberOfLines = $CmdLine[2]
Local $gInDrive, $gInDir, $gInFName, $gInExt, $gOutPath
Local $gMsgBoxTitle = "Error in " & #ScriptName
Local $InLine
Local $LineCount
Local $oFileIn
Local $oFileOut
Local $FileStringAppend
If FileExists($gInPath) Then
Else
MsgBox(4096, $gMsgBoxTitle, "This file does not exist" & #CRLF & $gInPath)
Exit
EndIf
_PathSplit($gInPath, $gInDrive, $gInDir, $gInFName, $gInExt)
If $NumberOfLines >= 1000000 Then
$FileStringAppend = $NumberOfLines / 1000000 & "M"
ElseIf $NumberOfLines >= 1000 Then
$FileStringAppend = $NumberOfLines / 1000 & "K"
Else
$FileStringAppend = $NumberOfLines
EndIf
$gOutPath = _PathMake($gInDrive, $gInDir, $gInFName & "_" & $FileStringAppend, $gInExt)
If FileExists($gOutPath) Then
MsgBox(4096, $gMsgBoxTitle, "File already exists" & #CRLF & $gOutPath)
Exit
EndIf
$oFileIn = FileOpen($gInPath, 0)
$oFileOut = FileOpen($gOutPath, 1)
; Check if file opened for reading OK
If $oFileIn = -1 Then
MsgBox(4096, $gMsgBoxTitle, "Unable to open file for read" & #CRLF & $gInPath)
Exit
EndIf
; Check if file opened for writing OK
If $oFileOut = -1 Then
MsgBox(4096, $gMsgBoxTitle, "Unable to open file for write." & #CRLF & $gOutPath)
Exit
EndIf
; Read in lines of text until the EOF is reached
$LineCount = 0
While 1
$InLine = FileReadLine($oFileIn)
$LineCount += 1
If #error = -1 Then ExitLoop
If $LineCount > $NumberOfLines Then ExitLoop
FileWriteLine($oFileOut, $InLine & #CRLF)
WEnd
FileClose($oFileIn)
FileClose($oFileOut)
Looking at the function documentation at this link - https://www.autoitscript.com/autoit3/docs/functions/FileWriteLine.htm . It appears you can leave off the & #CRLF in your FileWriteLine command.
AutoIt should use the same line terminator that is read in, or
"If the line does NOT end in #CR or #LF then a DOS linefeed (#CRLF)
will be automatically added."
Here's the solution I came up. It works, but I'm not sure it's the cleanest.
Opt("MustDeclareVars", 1) ;0 = no, 1 = require pre-declare
#include <File.au3>
#include <Array.au3>
Local $gInPath = $CmdLine[1]
Local $NumberOfLines = $CmdLine[2]
Local $gInDrive, $gInDir, $gInFName, $gInExt, $gOutPath
Local $gMsgBoxTitle = "Error in " & #ScriptName
Local $InLine
Local $LineCount
Local $oFileIn
Local $oFileOut
Local $FileStringAppend
Local Const $CHAR_READ_BLOCK = 100
Local $CharsRead = 0
Local $CrFound = 0
Local $LfFound = 0
Local $Newline
Local $InBlock
If FileExists($gInPath) Then
Else
MsgBox(4096, $gMsgBoxTitle, "This file does not exist" & #CRLF & $gInPath)
Exit
EndIf
_PathSplit($gInPath, $gInDrive, $gInDir, $gInFName, $gInExt)
If $NumberOfLines >= 1000000 Then
$FileStringAppend = $NumberOfLines / 1000000 & "M"
ElseIf $NumberOfLines >= 1000 Then
$FileStringAppend = $NumberOfLines / 1000 & "K"
Else
$FileStringAppend = $NumberOfLines
EndIf
$gOutPath = _PathMake($gInDrive, $gInDir, $gInFName & "_" & $FileStringAppend, $gInExt)
If FileExists($gOutPath) Then
MsgBox(4096, $gMsgBoxTitle, "File already exists" & #CRLF & $gOutPath)
Exit
EndIf
$oFileIn = FileOpen($gInPath, 0)
$oFileOut = FileOpen($gOutPath, 1)
; Check if file opened for reading OK
If $oFileIn = -1 Then
MsgBox(4096, $gMsgBoxTitle, "Unable to open file for read" & #CRLF & $gInPath)
Exit
EndIf
; Check if file opened for writing OK
If $oFileOut = -1 Then
MsgBox(4096, $gMsgBoxTitle, "Unable to open file for write." & #CRLF & $gOutPath)
Exit
EndIf
While $CrFound = 0 And $LfFound = 0
$CharsRead += $CHAR_READ_BLOCK
$InBlock = FileRead($oFileIn, $CharsRead)
If StringRight($InBlock, 1) = #CR Then
$InBlock = $InBlock & FileRead($oFileIn, $CharsRead)
EndIf
$CrFound = StringInStr($InBlock, #CR)
$LfFound = StringInStr($InBlock, #LF)
If $CrFound > 0 And $LfFound > 0 Then
$Newline = #CRLF
ElseIf $CrFound > 0 Then
$Newline = #CR
Else
$Newline = #LF
EndIf
WEnd
; Read first line of text
$InLine = FileReadLine($oFileIn, 1)
$LineCount = 1
FileWriteLine($oFileOut, $InLine & $Newline)
; Read in lines of text until the EOF is reached
While 1
$InLine = FileReadLine($oFileIn)
$LineCount += 1
If #error = -1 Then ExitLoop
If $LineCount > $NumberOfLines Then ExitLoop
FileWriteLine($oFileOut, $InLine & $Newline)
WEnd
FileClose($oFileIn)
FileClose($oFileOut)
I'm creating a script that will open a program , login , and do specific tasks .
I created the login script with a variables adding and loopin through .
The problem is with the program , sometimes it just gives you an error on connection or a network problem .
What I need is IF the script gets the problem it'll reset it self and go through the account it got the error on , This is what I have so far and I just can't make it work
$t = 0
$n = "account"
$p = "password"
For $r = X To X
Run("program")
AutoITSetOption("MouseCoordMode", 0)
AutoITSetOption("WinTitleMatchMode", 3)
Do
Sleep(1000)
$t = $t + 1
Until WinActive("program") Or $t = 15
$t = 0
Sleep(1500)
Send("{TAB}")
Sleep(100)
Send("{TAB}")
Sleep(100)
Send("{Enter}")
Sleep(100)
Send($n & $r)
Sleep(200)
Send("{TAB}")
Sleep(200)
Send($p & $r)
Sleep(100)
Send("{Enter}")
Sleep(5500)
If $t > 14 Then
$r = $r - 1
Run(#ComSpec & " /c taskkill /F /im program.exe")
Do
Sleep(500)
$t = $t + 1
Until WinActive("Program - Update News") Or $t = 15
$t = 0
WinActivate("Program")
Sleep(2000)
MouseClick("Primary", 28, 12)
Sleep(1000)
MouseClick("Primary", 35, 125)
Sleep(1000)
MouseClick("Primary", 360, 175)
Sleep(2000)
Send("{ENTER}")
Sleep(2500)
Run(#ComSpec & " /c taskkill /F /im program.exe")
; EndIf
Next
Right now what it does is reruns the program without actually closing the error window
Hopefully this will give you a better idea of how to create a script and fix your problem. It is commented to give you an understanding of the steps taken.
#include <msgboxconstants.au3>
Local $t = 0, $n = "account", $p = "password" ; $n & $p are your own data
Local $r = ["X", "X", "X"], $e, $msg, $w ;$r is filled with your own data
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("WinTitleMatchMode", 3)
HotKeySet("{ESC}", "Quit") ;If you want to exit the script, press the ESC key
Sender() ;call the function to run
While 1
If $e <> 0 Then ;if #error is set to a non-zero variable, wait 1 sec (1000 millisec) and run again
Sleep(1000)
Sender()
ElseIf $w = 0 Then ;if msgbox value is 0 AND retry OR ignore has been pressed, wait 1 second and run again
Sleep(1000)
$w += 1
Sender()
EndIf
WEnd
Func Sender() ;wrapped in function to make returning out of the function easier
For $r = "X" To UBound($r) ; for the first value in $r to the length of the array
Run("program")
$e = #error ;if Run sets #error then put #error and check the value with an if statement
If $e <> 0 Then
$msg = MsgBox(2, "ERROR", "error running program, exiting...")
If $msg = $IDABORT Then ;if we don't want to run the program again we abort
Quit()
ElseIf $msg = $IDRETRY Then ;if we want to retry then we hit retry
Return
ElseIf $msg = $IDIGNORE Then ;if we want to retry then we hit ignore as well
Return ;go out of the function because we have recieved an error and want to restart the function
EndIf
EndIf
SetError(0) ;sets #error to 0 so that we don't accidentally restart our program
Do
Sleep(1000)
$t += 1 ;add 1 to $t
Sleep(1500)
Send("{TAB}")
Sleep(100)
Send("{TAB}")
Sleep(100)
Send("{Enter}")
Sleep(100)
Send($n & $r)
Sleep(200)
Send("{TAB}")
Sleep(200)
Send($p & $r)
Sleep(100)
Send("{Enter}")
Sleep(5500)
If $t > 14 Then
$r -= 1 ;minus 1 from $r
Run(#ComSpec & " /c taskkill /F /im program.exe")
$e = #error
If $e <> 0 Then
$msg = MsgBox(2, "ERROR", "error running " & #ComSpec & " /c taskkill /F /im program.exe, Abort to Quit; Retry & Ignore to RETRY.")
If $msg = $IDABORT Then
Quit()
ElseIf $msg = $IDRETRY Then
Return
ElseIf $msg = $IDIGNORE Then
Return
EndIf
EndIf
EndIf
SetError(0)
Until WinActive("program") Or $t = 15
$t = 0 ;set $t to 0
Do
Sleep(500)
$t += 1
$w = WinActivate("Program")
If $w = 0 Then
$msg = MsgBox(2, "ERROR", "error activating program, Abort to Quit; Retry & Ignore to RETRY.")
If $msg = $IDABORT Then
Quit()
ElseIf $msg = $IDRETRY Then
Return
ElseIf $msg = $IDIGNORE Then
Return
EndIf
EndIf
$w += 1
Sleep(2000)
MouseClick("Primary", 28, 12)
Sleep(1000)
MouseClick("Primary", 35, 125)
Sleep(1000)
MouseClick("Primary", 360, 175)
Sleep(2000)
Send("{ENTER}")
Sleep(2500)
Run(#ComSpec & " /c taskkill /F /im program.exe")
$e = #error
If $e <> 0 Then
$msg = MsgBox(2, "ERROR", "error running " & #ComSpec & " /c taskkill /F /im program.exe, Abort to Quit; Retry & Ignore to RETRY.")
If $msg = $IDABORT Then
Quit()
ElseIf $msg = $IDRETRY Then
Return
ElseIf $msg = $IDIGNORE Then
Return
EndIf
EndIf
SetError(0)
Until WinActive("Program - Update News") Or $t = 15
Next
EndFunc ;==>Sender
Func Quit() ;will be called when we want to completely stop the script
Exit
EndFunc ;==>Quit
I'm in the process of making a small program to tell me on the fly how many employees are currently punched in via AvayaCMS Reporting.
Right now, the way that it is setup is that I have an Avaya script to take a quick report and export it in a CSV that is used by my Autoit script.
In terms of debugging it, I feel like I missing something and need another set of eyes.
launching the Staffing.au3 triggers the CSV script I'm using against the report. Even having the exact same data my message box still reports "0"
#include <Array.au3>
#include <CSV.au3>
$i_AgentCount = AvayaData(#ScriptDir & '\Report.csv', #ScriptDir & '\Name List.csv')
MsgBox(0x40, "", $i_AgentCount)
Func AvayaData($s_ReportSource, $s_NameList)
$av_LiveData = _ParseCSV($s_ReportSource)
If #error Then Return -1
$av_NameList = _ParseCSV($s_NameList)
If #error Then Return -1
Local $i_AgentCount = 0
For $i_RowCnt = 1 To (UBound($av_LiveData, 1) - 1) Step +1
For $i_AgtLst = 1 To (UBound($av_NameList) - 1) Step +1
If StringStripWS($av_LiveData[$i_RowCnt][1], 3) = StringStripWS($av_NameList[$i_AgtLst][0], 3) Then
$i_AgentCount += 1
EndIf
Next
Next
;Return the Agent Count
Return $i_AgentCount
EndFunc
Name List.csv
Agent Name
"Doe, Jane"
"Doe, John"
Report.csv
,Agent Name,Login ID,Extn,AUX Reason,State,Split/Skill,Time,VDN Name
5,"Doe, John",5930001,1000001,7,AUXOUT,999,51:32:00,
2,"Doe, Jane",5930002,1000002,7,AUXOUT,999,52:32:00,
Tested! It works well with the files supplied (copied them and names them as in your script)
please note the followings
_ParseCsv() has been rewritten add parameters like $Dchar as delimeter etc. (see script)
Note how I locate the names in the file (you can easily add feature to extend search but it won't be becessary)
msgboxes are for explanatory purposes; comment them out if not need them anymore
array.au3 is not needed
and the code:
$i_AgentCount = AvayaData(#ScriptDir & '\Report.csv', #ScriptDir & '\Name List.csv')
MsgBox(0x40, "", $i_AgentCount)
Func AvayaData($s_ReportSource, $s_NameList)
$av_LiveData = _ParseCSV($s_ReportSource,",","oops...",True)
If #error Then Return -1
$av_NameList = _ParseCSV($s_NameList,",","oops: 2",True)
If #error Then Return -1
MsgBox(0,default,"$av_NameList (Number of lines) -> " & $av_NameList[0][0])
MsgBox(0,default,"$av_NameList (Number of data in each line) -> " & $av_NameList[0][1])
MsgBox(0,default,"$av_LiveData (Number of lines) -> " & $av_LiveData[0][0])
MsgBox(0,default,"$av_LiveData (Number of data in each line) -> " & $av_LiveData[0][1])
Local $i_AgentCount = 0
for $i = 1 to $av_NameList[0][0] Step 1
For $j= 1 To $av_LiveData[0][0] Step 1
;we can have names from $av_NameList as well from $av_LiveData but in Live Data 2nd abd 3rd values are the names
MsgBox(0,default,$av_NameList[$i][1] & $av_NameList[$i][2] & " <------------> " & $av_LiveData[$j][2] & $av_LiveData[$j][3])
;~ let's compare them if matched with any of the liveData lines
If StringCompare($av_NameList[$i][1] & $av_NameList[$i][2],$av_LiveData[$j][2] & $av_LiveData[$j][3]) == 0 Then
$i_AgentCount += 1
MsgBox(0,default,"Match found: counter: " & $i_AgentCount)
EndIf
Next
Next
;Return the Agent Count
Return $i_AgentCount
EndFunc
Func _ParseCSV($f,$Dchar,$error,$skip)
Local $array[500][500]
Local $line = ""
$i = 0
$file = FileOpen($f,0)
If $file = -1 Then
MsgBox(0, "Error", $error)
Return False
EndIf
;skip 1st line (since it is the header)
If $skip Then $line = FileReadLine($file)
While 1
$i = $i + 1
Local $line = FileReadLine($file)
If #error = -1 Then ExitLoop
;skip 1st line
$row_array = StringSplit($line,$Dchar)
If $i == 1 Then $row_size = UBound($row_array)
If $row_size <> UBound($row_array) Then MsgBox(0, "Error", "Row: " & $i & " has different size ")
$row_size = UBound($row_array)
$array = _arrayAdd_2d($array,$i,$row_array,$row_size)
WEnd
FileClose($file)
$array[0][0] = $i-1 ;stores number of lines
$array[0][1] = $row_size -1 ; stores number of data in a row (data corresponding to index 0 is the number of data in a row actually that's way the -1)
Return $array
EndFunc
Func _arrayAdd_2d($array,$inwhich,$row_array,$row_size)
For $i=1 To $row_size -1 Step 1
$array[$inwhich][$i] = $row_array[$i]
Next
Return $array
EndFunc
#region ;************ Includes ************
#include "csv.au3"
#include <Array.au3>
#endregion ;************ Includes ************
$i_AgentCount = AvayaData(#ScriptDir & '\Report.csv', #ScriptDir & '\Name List.csv')
MsgBox(0x40, "", $i_AgentCount)
Func AvayaData($s_ReportSource, $s_NameList)
Local $i_AgentCount = 0
Local $s = FileRead($s_NameList)
Local $loggedInNames = FileRead($s_ReportSource)
$av_NameList = _ParseCSV($s_NameList)
If #error Then Return -1
;~ _ArrayDisplay($av_NameList)
ConsoleWrite($s & #CRLF)
For $i = 1 To UBound($av_NameList) - 1
ConsoleWrite($i & " " & $av_NameList[$i][0] & #CRLF)
If StringInStr($s, $av_NameList[$i][0]) <> 0 Then
$i_AgentCount += 1
EndIf
Next
Return $i_AgentCount
EndFunc ;==>AvayaData
Is there a way to quickly list which sites are on which IP address in IIS 7?
If I remember correctly you could sort a view of domains by IP in IIS 6 which was a big help to me in seeing which IPs I had available.
Take a look at APPCMD .
For example, to list all sites on the machine, use this command-line:
%systemroot%\system32\inetsrv\APPCMD list sites
You can try this script:
MachineName = "localhost"
IIsObjectPath = "IIS://" & MachineName & "/w3svc"
WScript.Echo "Checking : " & IISObjectPath
Set IIsObject = GetObject(IIsObjectPath)
for each obj in IISObject
if (Obj.Class = "IIsWebServer") then
BindingPath = IIsObjectPath & "/" & Obj.Name
Set IIsObjectIP = GetObject(BindingPath)
wScript.Echo BindingPath & " - " & IISObjectIP.ServerComment
ValueList = IISObjectIP.Get("ServerBindings")
ValueString = ""
For ValueIndex = 0 To UBound(ValueList)
value = ValueList(ValueIndex)
Values = split(value, ":")
IP = values(0)
if (IP = "") then
IP = "(All Unassigned)"
end if
TCP = values(1)
if (TCP = "") then
TCP = "80"
end if
HostHeader = values(2)
if (HostHeader <> "") then
wScript.Echo " IP = " & IP & " TCP/IP Port = " & TCP & ", HostHeader = " & HostHeader
else
wScript.Echo " IP = " & IP & " TCP/IP Port = " & TCP
end if
Next
wScript.Echo ""
set IISObjectIP = Nothing
end if
next
set IISObject = Nothing
(source www.iisfaq.com)