Skip to content

Instantly share code, notes, and snippets.

View dhcgn's full-sized avatar

Daniel dhcgn

View GitHub Profile
@dhcgn
dhcgn / gist:2f0d4b4d1f08088c438e
Created September 13, 2014 21:42
C# PSCmdlet RuntimeDefinedParameter usage
[Cmdlet(VerbsData.Export, "AsQrCode")]
public class ExportAsQrCode : PSCmdlet, IDynamicParameters
{
private static RuntimeDefinedParameterDictionary _staticStroage;
public object GetDynamicParameters()
{
IEnumerable<string> brushes = typeof (Brushes).GetProperties().Select(x => x.Name);
var runtimeDefinedParameterDictionary = new RuntimeDefinedParameterDictionary();
string stderr;
string stdout;
string url="\"https://api.telegram.org/bot[API_KEY]/sendMessage?chat_id=-[CHATID]&text=HomeMatic: Haustuer wurde geoeffnet!\"";
system.Exec("wget --no-check-certificate -q -O - "#url, &stdout, &stderr);
public static byte[] ExtractResource(string filename)
{
var assembly = Assembly.GetExecutingAssembly();
var name = assembly.GetManifestResourceNames().Single(s => s.EndsWith(filename));
var stream = assembly.GetManifestResourceStream(name);
var ms = new MemoryStream();
stream.CopyTo(ms);
@dhcgn
dhcgn / CreateRandomData.cs
Last active August 1, 2016 14:50
Create Random Data with c#
using System;
using System.IO;
using System.Linq;
namespace CreateRandomData
{
class Program
{
static void Main(string[] args)
{
@dhcgn
dhcgn / TestForSubdomains.ps1
Last active June 26, 2016 09:27
Powershell script to test a domain for most common subdomains
$serverName = "example.org"
$url = 'https://raw.githubusercontent.com/rbsec/dnscan/master/subdomains-10000.txt'
$subdomains = ((Invoke-WebRequest -Uri $url -UseBasicParsing).Content).Split("`n")
$subdomainsCount = $subdomains.Length
Write-Host ('Will test {0} entries' -f $subdomainsCount)
$count = 1
@dhcgn
dhcgn / Test-TCPPortConnection.ps1
Last active August 5, 2016 11:06
powershell script to test the response of a computer to a specific TCP port (After Windows 8.1 use Test-NetConnection)
<#
.SYNOPSIS
Test the response of a computer to a specific TCP port
.DESCRIPTION
Test the response of a computer to a specific TCP port
.PARAMETER ComputerName
Name of the computer to test the response for
gci C:\inetpub\logs\LogFiles | # Get all sites
%{ gci $_.FullName | Sort-Object LastWriteTime | select -Last 1 } | # Get the last log file from each site
?{$_.LastWriteTime -gt (Get-Date).Date} | # only files from today
Get-Content -Tail 5 | # get the last lines
Select-String -Pattern 'POST' | # only method POST
Sort-Object # sort ASC
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using NUnit.Framework;
using ProtoBuf;
namespace EncryptionSample
{
void Main()
{
{ // 0. Create a HMAC
byte[] keyHmac = new byte[] { 255 };
var hmac = new HMACSHA512(keyHmac); // 1st HMACSHA512 ctor
var result = hmac.ComputeHash(new byte[] { 1, 2, 3 });
Console.Out.WriteLine($"0. - {Convert.ToBase64String(result)}");
}
Console.Out.WriteLine("\r\nThe following MACs should be all equal!\r\n");
$pathOld = 'C:\Users\user\Documents\old.ics'
$pathNew = 'C:\Users\user\Documents\new.ics'
(Get-Content $pathOld -Encoding UTF8) |
% {$_ -replace '^UID:.{36}', ("UID:{0}" -f ([System.Guid]::NewGuid().ToString())) } |
Out-File $pathNew -Encoding utf8