Skip to content

Instantly share code, notes, and snippets.

@changbowen
changbowen / get_cdp.py
Last active August 16, 2019 07:36
Getting CDP (Cisco Discovery Protocol) information via Python on specified list of ESXi hosts
#!/usr/bin/env python
import sys
import atexit
from pyVim.connect import SmartConnectNoSSL, Disconnect
import pyVmomi
from pyVmomi import vim
from typing import List, Dict, Union
from tabulate import tabulate
from getpass import getpass
public static class NativeMethods
{
[DllImport("user32.dll")]
private static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData);
private delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref Rect2 lprcMonitor, IntPtr dwData);
[DllImport("user32.dll")]
private static extern bool GetMonitorInfo(IntPtr hwnd, ref MonitorInfo mInfo);
[DllImport("Shcore")]
@changbowen
changbowen / Get-CDP.ps1
Last active March 13, 2020 09:22
Getting CDP (Cisco Discovery Protocol) information via PowerShell on specified list of ESXi hosts
<#
.SYNOPSIS
Get CDP information from one or more ESX hosts.
.PARAMETER VMHost
VMHost can be a list of the below entries:
- FQDN name of the host
- VMware.Vim.HostSystem (return type of 'Get-View -ViewType HostSystem')
- VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl (return type of 'Get-VMHost')
function ipChangeHandler {
Write-Host "Detected an IP change..."
Write-Host "Collecting connections information..."
$connObjs = New-Object System.Collections.ArrayList
$ints = Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp -AddressState Preferred
foreach ($int in $ints) {
$_alias = $int.InterfaceAlias
$_index = $int.InterfaceIndex
$_ipaddr = $int.IPAddress
$intCfg = $int | Get-NetIPConfiguration
@changbowen
changbowen / wipe_disk_and_check_bad_sectors.sh
Last active May 27, 2019 09:02
Wipe disk and check bad sectors
# check physical and logical sector size
lsblk -o Name,PHY-SEC,LOG-SEC
# wipe disk
sudo shred -v -n1 -z /dev/sdx
# check bad sectors (readonly)
sudo badblocks -vs -b 4096 -c 65536 /dev/sdx
# check bad sectors and wipe disk
@changbowen
changbowen / docker cheatsheet
Created April 26, 2019 07:03
docker cheatsheet
# testing
docker run -it --rm busybox sh
git checkout --orphan latest_branch # orphan omits all the history
git add * # if you want to include all files (respecting gitignore). Otherwise make other changes here.
git commit -am "commit message"
git branch -D master # delete master branch
git branch -m master # rename current branch to master
git push -f origin master
@changbowen
changbowen / ObservableKeyedCollection.cs
Last active November 14, 2023 06:05
Observable KeyedCollection with support for data binding and key updating
//KeyedCollection keeps an internal lookup dictionary for better performance.
//With normal implementations of an observable KeyedCollection, when used for
//data bindings in WPF, once the key of the item is changed with bindings, the
//corresponding key internal dictionary is not changed, which leads to hidden
//problems when the dictionary is used.
//Below is a custom implementation of KeyedCollection to solve that problem.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;