convert DHCP IP to static


%pre --interpreter=busybox
# extract network info from bootup
VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}")
IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}')
NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}')
GATEWAY=$(esxcfg-route | awk '{print $5}')
HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}')
echo "network --bootproto=static --addvmportgroup=true --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME}" > /tmp/networkconfig


$int1 = Get-WmiObject -Query "select * from Win32_networkadapterconfiguration where dhcpenabled = true and ipenabled = true" | select-object -first 1
$int2 = Get-WmiObject -Query "Select * from Win32_NetworkAdapter where MACAddress = '$($int1.MACAddress)'"
write-host $($int1.IPAddress[0]), $($int1.IPSubnet[0]), $($int1.DefaultIPGateway[0]), $($int2.NetConnectionID), $($int1.DNSServerSearchOrder[0])
&netsh interface ipv4 set address `"$($int2.NetConnectionID)`" static $($int1.IPAddress[0]) $($int1.IPSubnet[0]) $($int1.DefaultIPGateway[0])
&netsh interface ipv4 add dnsservers `"$($int2.NetConnectionID)`" $($int1.DNSServerSearchOrder[0]) validate=no
&netsh interface ipv4 add dnsservers `"$($int2.NetConnectionID)`" $($int1.DNSServerSearchOrder[1]) index=2 validate=no

Figure out when a system was installed

ll /var/adm/ras/bosinstlog

get-vmhost | sort name | foreach {$h = $_.Name; $d = (Get-EsxCli -VMHost $h).software.vib.list() | sort InstallDate | select -first 1; write-host $h,$d.InstallDate;}
ll /dev/config
echo "sel dev 1;info;wait;il"|/usr/sbin/cstm

rpm -qi basesystem
rpm -qi filesystem
head /var/log/installer/syslog

ll /var/sadm/system/logs
/usr/sbin/prtconf | head

systeminfo | findstr Original

count pages for all docs in a folder

$word = New-Object -ComObject word.application
$word.visible = $false
$pages = 0
try {
 Get-ChildItem -path "." | ? {$ -match ".*\.docx{0,1}$"} | foreach-object {
  write-host $
  # fullName, confirmConversion, readOnly, addToRecent, passwordDocument
  $doc = $$_.fullname, $false, $true, $false, "")
  $window = $doc.ActiveWindow; $panes = $window.Panes; $pane = $Panes.item(1)
  $pages += $pane.pages.count
  write-host $pages
} finally { $word.Quit() }

Solaris – what process is listening on each port?

Since Solaris doesn’t have a ‘netstat -tunlp’, the below parses the output of ptree and pfiles to get a list:

my %apps;
open(T, "ptree |"); while() { $apps{$1}->{"cmd"}=$2 if(/(\d+)\s+(.*)/) }; close(T);
foreach my $p (sort keys %apps) {
my @ports; open(F, "pfiles $p 2>/dev/null |");
while() { push(@ports,$1."/".$2) if(/sockname.*?AF_INET[6?]\s+(.*?)\s+port: (\d+)/) }
my %h=map { $_, 1 } @ports; @ports=keys %h; $apps{$p}->{"ports"}=join(", ",@ports); close(F);
foreach $p (sort {$apps{$a}->{"cmd"} cmp $apps{$b}->{"cmd"}} keys %apps) {
printf("%-5s %-30.32s\t%-20s\n",$p,$apps{$p}->{"cmd"},$apps{$p}->{"ports"}) if length($apps{$p}->{"ports"})>0;
Continue reading "Solaris – what process is listening on each port?"

hunting for a random string

.. in a large (and completely undocumented) database, I’ve found the ways to get all tables that have a column name like ‘string’ and all rows that contain a string. A bit more optimized than my previous search&replace example.

select as tname, SCHEMA_NAME(schema_id) as sname, as cname
from sys.tables t join sys.columns c
on t.object_id=c.object_id
where like '%dns%'
order by sname, tname
EXEC SearchTables @Tablenames = '%',@SearchStr = 'host%'

Continue reading “hunting for a random string”

Bad Behavior has blocked 203 access attempts in the last 7 days.