Get external IP address create html and ftp update upload web page
This grabs the IP address from the web page creates a html file then uploads
the file to your webhost.
Things that are required to make this work:
Schedule as task ( option but recommended )
Change web file location to a location you will keep, it will store the html file there before upload
Change your web server information
Input the username and password
$webfile = "C:\Scripts\files\myindex.html"
function GetIP {
$source = "http://checkip.dyndns.com/"
$client = new-object System.Net.WebClient
$webpage = $client.downloadString($source)
$lines = $webpage.split("`n")
[void]($webpage -split "`n" | ? {$_ -match "\d*\.\d*\.\d*\.\d*"});
$ip = $Matches[0]
$obj = New-Object Object
$obj | Add-Member Noteproperty externalIP -value $ip
$obj
}
#exporttoweb
if (Test-Path -Path $webfile ) {
Remove-Item ($webfile)
}
$head = "<style>"
$head = $head + "BODY{background-color:#9FAEB5;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#999999}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$head = $head + "</style>"
GetIP | ConvertTo-HTML -head $head -body ("<H2>My Info Site</H2>") | Out-File $webfile
$ftp = [System.Net.FtpWebRequest]::Create("ftp://yourwebsite.com/webfile.html")
$ftp = [System.Net.FtpWebRequest]$ftp
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$ftp.Credentials = new-object System.Net.NetworkCredential("username","password")
$ftp.UseBinary = $true
$ftp.UsePassive = $true
$content = [System.IO.File]::ReadAllBytes($webfile)
$ftp.ContentLength = $content.Length
$rs = $ftp.GetRequestStream()
$rs.Write($content, 0, $content.Length)
$rs.Close()
$rs.Dispose()