Skip to content

Instantly share code, notes, and snippets.

Steven Swenson ctigeek

Block or report user

Report or block ctigeek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ctigeek
ctigeek / Enable-DynamicIpThrottling.ps1
Created Jul 26, 2017
Enable dynamic IP throttling in IIS.
View Enable-DynamicIpThrottling.ps1
function Enable-DynamicIpThrottling($webSiteName, [bool] $enabled, [int]$maxRequests, [int]$intervalMilliseconds, [bool] $loggingOnly = $false) {
##https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/dynamicipsecurity/
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/dynamicIpSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableLoggingOnlyMode", $loggingOnly)
$requestRate = $cpSecConfig.ChildElements["denyByRequestRate"]
@ctigeek
ctigeek / Enable-IpSecurityProxyMode.ps1
Created Jul 26, 2017
Enable proxy mode in the IP security settings in IIS.
View Enable-IpSecurityProxyMode.ps1
function Enable-IpSecurityProxyMode($websiteName) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableProxyMode",$true)
$manager.CommitChanges();
$manager.Dispose()
@ctigeek
ctigeek / Add-IpToIisBlacklist.ps1
Last active Jul 26, 2017
Add an IP address to a black-list for an IIS website.
View Add-IpToIisBlacklist.ps1
function Add-IpToIisBlacklist($websiteName, $ip, $subnetMask = $null) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecCollection = $cpSecConfig.GetCollection()
$newAdd = $cpSecCollection.CreateElement("add")
$newAdd["ipAddress"] = $ip
if ($subnetMask) {
@ctigeek
ctigeek / Get-DomainsAltAlias.ps1
Created May 24, 2017
Get all domains and alias/alternate domains from CP REST API.
View Get-DomainsAltAlias.ps1
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) {
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss");
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret);
$sha1 = [System.Security.Cryptography.SHA1]::Create();
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign));
$signature = [System.Convert]::ToBase64String($signedBytes);
$sha1.Dispose()
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
}
@ctigeek
ctigeek / Load-WhoisServers.ps1
Created Apr 11, 2017
Load whois servers from @weppos's repo.
View Load-WhoisServers.ps1
if (-not $hostMap) {
$whoisHostMapUrl = "https://raw.githubusercontent.com/weppos/whois/master/data/tld.json"
$raw = Invoke-RestMethod $whoisHostMapUrl
$hostMap = @{}
$raw.psobject.Properties | ?{ $_.Value.host } | Foreach { $hostMap[$_.Name] = $_.Value.host }
}
## $hostMap["com"] will return whois.verisign-grs.com
@ctigeek
ctigeek / MockDatabaseHelper.cs
Last active Dec 30, 2016
Helper class for mocking a DbProviderFactory
View MockDatabaseHelper.cs
// I've moved this to a full repo:
// https://github.com/ctigeek/SqlUnitTestHelper
@ctigeek
ctigeek / Periodic.cs
Created Dec 5, 2016
Run an Action periodically....
View Periodic.cs
public class Periodic : IDisposable
{
private static readonly object lockObject = new object();
private readonly List<PeriodicEvent> history = new List<PeriodicEvent>();
private readonly Action action;
private readonly Timer timer;
private long id = 0;
public PeriodicEvent LatestEvent { get; private set; }
@ctigeek
ctigeek / Get-ResponseCode.ps1
Created Nov 1, 2016
GET the response code from a URL.
View Get-ResponseCode.ps1
function Get-ResponseCode($url) {
try {
$response = Invoke-WebRequest $url
$response.StatusCode
}
catch {
$_.Exception.Response.StatusCode.Value__
}
}
@ctigeek
ctigeek / RunStuffAndWait.cs
Last active Nov 1, 2016
Run stuff and wait in program.cs
View RunStuffAndWait.cs
class Program
{
static void Main(string[] args)
{
ManualResetEventSlim manualResetEvent = null;
Console.CancelKeyPress += (sender, eventArgs) =>
{
Console.WriteLine("cancel!");
manualResetEvent?.Set();
@ctigeek
ctigeek / Stop-ServiceAndWaitForItToDie.ps1
Last active Dec 11, 2017
Stop a windows service. Wait for the process to die. Option to kill it if it doesn't stop.
View Stop-ServiceAndWaitForItToDie.ps1
function Stop-ServiceAndWaitForItToDie {
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[object] $Service,
[Parameter(Mandatory=$False,ValueFromPipeline=$False)]
[int] $TimeoutInSeconds = 30,
[Parameter(Mandatory=$False,ValueFromPipeline=$False)]
[Switch] $KillAfterTimeout,
[Parameter(Mandatory=$False,ValueFromPipeline=$False)]
You can’t perform that action at this time.