
' Written by Adam Saunders
' Whilst sipping a bottle of Nottage Hill Shiraz 1999 (Excuse any typos ;)

Option Explicit
Dim IISOBJ, Bindings, Parts, NewBinding, OldIP, NewIP, Site
Dim values, pos, setPort

' The IP Addresses. Will only replace Old with New
OldIP = "2.2.2.2"
NewIP = "3.3.3.3"
setPort = "80" 'set to be blank if to keep old port values


Set IISOBJ = GetObject("IIS://LocalHost/W3SVC") 
for each Site in IISOBJ
	if (Site.Class = "IIsWebServer") then

		Bindings = Site.ServerBindings
		WScript.Echo "Server bindings : " & site.AdsPath 
		WScript.Echo "Server Comment  : " & site.ServerComment
		WScript.Echo "========================================" 
	 
		If (ubound(Bindings) <> -1) then
			For pos = lbound(Bindings) To uBound(Bindings)
				Wscript.echo "Current Header : " & Bindings(pos)
				NewBinding = ""
				Values = split(Bindings(pos), ":")
				NewBinding = NewIP & ":"
				If len(setPort)>0 then
					NewBinding = NewBinding & setPort 
				Else
					NewBinding = NewBinding & values(1) 
				End If
				NewBinding = NewBinding & ":" & values(2)
				If values(0) = OldIP Then
					WScript.Echo Bindings(pos) & " -> " & NewBinding
					Bindings(pos) = NewBinding
				End If
			Next	
			Site.PutEx 2, "ServerBindings", Bindings
			Site.SetInfo 
		End If 
		WScript.Echo

	end if
next
