Archive for the ‘*nix’ Category
Posted by jpluimers on 2021/07/27
This is a continuation of yesterdays
Listing information on all active interfaces on MacOS part 1: getting the active interface names.
It is based on ideas in these StackExchange posts:
I threw most of the implementation details in the ideas away, as they were way to much based on empirical trial and error, than proper research.
So I tried doing the research and came up with the things below.
Getting the IPv4 address and DHCP/BOOTP information of a NIC
By using the ipconfig command, you can get specific details for a NIC like an IPv4 (with the getifaddr) or DHCP (with the getpacket option to get the latest DHCP packet):
for i in $(ifconfig -l -u); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done | xargs -n1 -I_nic_ sh -c 'echo "_nic_: $(ipconfig getifaddr _nic_)"'
or DHCP/BOOTP:
for i in $(ifconfig -l -u); do if ifconfig $i | grep -q "status: active" ; then echo $i; fi; done | xargs -n1 -I_nic_ sh -c 'echo "_nic_: $(ipconfig getpacket _nic_)"'
The latter returns a very long list, which I wanted to shorten into a more readable format.
ipconfig syntax
You can find more information in the [Archive.is] ipconfig(8) [osx man page] / [WayBack] ipconfig Man Page – macOS – SS64.com excerpt:
Read the rest of this entry »
Posted in *nix, *nix-tools, Apple, bash, Development, DNS, ifconfig, Mac OS X / OS X / MacOS, Power User, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/22
A few years back, Ken Thompson’s 1980 Unix password got cracked.
It took that long because his password p/q2-q4! had enough entropy by using uncommon characters so the crypt(3) based hash ZghOT0eRm4U9s was hard to crack.
The password was an opening chess move noted in the variety of the descriptive notation. A shorter notation would have been P-Q4, which would require months to crack in that era.
In modern chess notation, it would be 1. d4, moving the Queen’s Pawn from d2 to d4.
References (many interesting messages in the TUHS thread below):
Read the rest of this entry »
Posted in *nix, B, C, Development, Power User, Security, Software Development | Leave a Comment »
Posted by jpluimers on 2021/07/21
On one of my Raspberry Pi boxes, somehow I could not access files over SFTP (SSH File Transfer Protocol) via FileZilla.
I would consistently get this error:
"Connection timed out after 20 seconds of inactivity"
Figuring the exact cause took a while.
TL;DR: SFTP uses an interactive non-login shell, then interprets the output from that shell. For that kind of shell, ensure few or none scripts run that output text.
These links finally got me to the cause
Read the rest of this entry »
Posted in *nix, *nix-tools, bash, bash, Communications Development, Conference Topics, Conferences, Development, Event, Internet protocol suite, Power User, Scripting, SFTP, Software Development, SSH, TCP | Leave a Comment »
Posted by jpluimers on 2021/07/19
[WayBack] windows – Is there any sed like utility for cmd.exe? – Stack Overflow
TL;DR: many people suggest to use PowerShell, but there is GNU sed in Chocolatey
The chocolatey part:
The PowerShell part: read the other answers from the above question.
–jeroen
Posted in *nix, *nix-tools, CommandLine, Power User, PowerShell, RegEx, sed, Windows | Leave a Comment »
Posted by jpluimers on 2021/07/09
Based on
This scans the 192.168.1.0/24 network for SMB capable machines, and extracts information from them:
nmap -p139,445 --script smb-os-discovery 192.168.1.0/24
Note that experimenting this, I found out that nmap is also available on Chocolatey: [WayBack] Chocolatey Gallery | Nmap 7.70 (heck, since 2016, no less!).
I was hoping I wrote a little batch file around this, called find-smb-hosts.on.192.168.1.network.bat, because net view is working not so well on Windows 10 any more, but that failed, so here is the batch file:
@echo off
:: only works from older versions than Windows 10
:: the delay is caused by the "net view" scanning the network
:: the first for calls ping with the hostname
:: the second for gets the IP and hostname without waiting for a ping result
for /f "usebackq tokens=1* delims=\ " %%m in (`net view ^| findstr "\\"`) do (
for /f "usebackq tokens=2,3 delims=[] " %%h in (`ping -4 %%m -n 1 -w 1 ^| grep Pinging`) do (
echo %%i %%h
)
)
goto :eof
:: output of the first for without filtering (no starting newline):
:: Server Name Remark
::
:: -------------------------------------------------------------------------------
:: \\REVUE Samba 4.7.3-git.30.54c196e5d35SUSE-oS15.5-x86_64
:: \\VCS-CI
:: The command completed successfully.
:: output of the second for without filtering (including the starting newline):
::
:: Pinging revue [192.168.1.62] with 32 bytes of data:
:: Reply from 192.168.1.62: bytes=32 time<1ms TTL=64
::
:: Ping statistics for 192.168.1.62:
:: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
:: Approximate round trip times in milli-seconds:
:: Minimum = 0ms, Maximum = 0ms, Average = 0ms
The above batch file delivered many more results than this line:
nmap -p139,445 --script smb-os-discovery 192.168.71.1/24 | grep -w "\(report\|Computer name\)"
–jeroen
Posted in *nix, *nix-tools, nmap, Power User | Leave a Comment »
Posted by jpluimers on 2021/06/28
From [WayBack] How to rename a VM through SSH on ESXi ? |VMware Communities (numbering and code highlighting mine):
Kindly find the below:
- Backup the virtual machine
- Power down the virtual machine
- Remove the virtual machine from the vSphere host inventory
- Open an SSH console session to the vSphere host
- Navigate to the storage directory containing the virtual machine: For example:
cd /vmfs/volumes/<datastore_name>/<original_vmname>
- Rename the primary
.vmdk configuration files: vmkfstools -E "<original_vmname>.vmdk" "<new_vmname>.vmdk"
- Rename the
.vmx configuration file: mv "original_vmname.vmx" "new_vmname.vmx"
- Edit the virtual machine .vmx configuration file (Be sure to properly update the directory and file name of the
.vswp swap file reference): vi "new_vmname.vmx"
- Rename any remaining files in the virtual machine’s folder as needed:
- Rename the
.vmxf configuration file: mv "original_vmname.vmxf" "new_vmname.vmxf"
- Rename the
.nvram configuration file: mv "original_vmname.nvram" "new_vmname.nvram"
- Rename the
.vsd configuration file: mv "original_vmname.vsd" "new_vmname.vmsd"
- Rename the virtual machine folder: Move up one directory level to the parent folder (
cd .. ) then rename the virtual machine directory: mv "original_directory" "new_directory"
- Add the newly-named virtual machine to the host’s inventory (the newly renamed
.vmx configuration file)
- Power on the newly renamed virtual machine
- Answer “I moved it” to the virtual machine question prompt (not “I copied it”)
- Review the virtual machine and all files/folders to make sure it is named as desired and functioning properly
Note: There are other methods to allow for renaming, but this method is fairly quick and easy. It should work on all editions of vSphere from free to Enterprise Plus.
The “Answer question” prompt where you should selected “I moved it”:
-> 
Prompt with symlink names in the path
On a site note, I need to figure uit how to set the ESXi shell prompt to show the current path like pwd does (with symlink names in it instead of the followed symlink targets):
[root@ESXi-X9SRI-3F:~] cd /vmfs/volumes/EVO860_250GB/
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] pwd
/vmfs/volumes/EVO860_250GB
The ESXi shell is based on busybox, in fact it uses the ash variety:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] `readlink -f \`which readlink\`` | grep ^BusyBox
BusyBox v1.29.3 (2018-11-02 15:37:50 PDT) multi-call binary.
BusyBox is copyrighted by many authors between 1998-2015.
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] type chdir
chdir is a shell builtin
This seemed to work fine:
[root@ESXi-X9SRI-3F:/vmfs/volumes/5c9bd516-ef1f6d4c-f1b1-0025907d9d5c] PS1="[\u@\h:`pwd`] "
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
But in faxt fails, as it only takes a pwd value once, and not every time the prompt is evaluated:
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] cd ..
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB] pwd
/vmfs/volumes
[root@ESXi-X9SRI-3F:/vmfs/volumes/EVO860_250GB]
So I need to re-visit these links:
- Identifying disks when working with VMware ESXi/ESX (1014953)
- Downloading files with wget on ESXi · random writes (explaining the BusyBox version trick)
- busybox prompt – Google Search
- [WayBack] shell – What are special prompt symbols for busybox’s sh support? – Unix & Linux Stack Exchange
BusyBox has two shells, ash and hush. To see which one you have, run type chdir: ash has it as a builtin (synonymous with cd), hush doesn’t. Both have an optional prompt expansion feature. Ash’s is enabled by activating the ASH_EXPAND_PRMT feature at compile time, while hush requires FEATURE_EDITING_FANCY_PROMPT.
When that feature is present, in ash the value of PS1 is expanded like a double-quoted string: $foo, $(command) and `command` constructs are expanded.
Some backslash escapes are processed (in ash, after substitutions). They are a subset of bash’s.
\!: line history count
\a: bell
\b: backspace
\e, \E: escape
\f: form feed
\h: host name
\n: newline
\r: carriage return
\t: tab
\u: user name (only with FEATURE_GETUSERNAME_AND_HOMEDIR)
\v: vertical tab
\w: current directory, with ~ for the home directory (only with FEATURE_GETUSERNAME_AND_HOMEDIR)
\W: current directory (unabbreviated)
\xHH or \XHH where HH are two hexadecimal digits: a character given by its hex code
\[…\]: the enclosed text doesn’t count for width calculation purposes
(If you’re looking at the source code, this happens in parse_and_put_prompt in libbb/lineedit.c.)
- [WayBack] shell – busybox ash PS1 not expanding – Unix & Linux Stack Exchange
- [WayBack] Quick Tip – How to Change ESXi SSH Prompt
- [WayBack] shell – How to display current path in command prompt in linux’s sh (not bash)? – Super User
–jeroen
Posted in *nix, *nix-tools, BusyBox, ESXi6, ESXi6.5, ESXi6.7, Power User, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/06/07
Posted in *nix, Cloud Key, ESXi6, ESXi6.5, ESXi6.7, Internet, Network-and-equipment, Power User, Unifi-Ubiquiti, Virtualization, VMware, VMware ESXi | Leave a Comment »
Posted by jpluimers on 2021/05/31
Reminder to self to check if wget on ESXi now finally supports https downloading: [WayBack] Downloading files with wget on ESXi · random writes.
In the mean time, ESXi 6.7 Update 2 and up seems to support this; so the below workaround might only be needed for ESXi 6.7 update 1 and below.
[WayBack] VMware ESXi: help downloading large ISO – Server Fault
I will likely not do this, as by now all my ESXi boxes should have been recent enough.
I will keep the article because of the BusyBox commands section below.
If so, I might finally try and write a Python wrapper for this, as I know that Python 3 on ESXi supports https, but the ESXi BusyBox does not have a built-in cURL.
Some links and notes I might need by then:
BusyBox commands
Another cool thing in the above blog post is that it shows how to dump the BusyBox built in commands.
I ran it for ESXi 6.7 with a slight trick to get the full path (using back-ticks and escaped back-ticks) and content.
Since ESXi is BusyBox based, the commands that are in /bin are not actually binaries, but each command is a symlink to the BusyBox binary. BusyBox then knows the original name of the command, so it can deduct what part to execute. This makes for a very space efficient storage scheme.
The various bits of the tricks to get the location of the BusyBox binary, so the --list parameter can be passed to it:
- The
which wget gives the full path of wget.
- The
ls -l `which wget` shows the full path of wget and the symlink target (but there is no way for ls to only show the symlink target).
- The
readlink -f `which wget` shows the full path of where /bin/wget points to: the BusyBox binary.
The main trick consists of backtick evalution, and knowing that ls cannot get you just the symlink target, but readlink can:
Now the back-tick escapes, because you cannot nest back-ticks:
- The
`readlink -f \`which wget\`` executes the BusyBox binary without arguments.
- The
`readlink -f \`which wget\`` --list executes the BusyBox binary with the --list parameter.
Note I do not like the cat --help (see [WayBack] How do I check busybox version (from busybox)? – Unix & Linux Stack Exchange) way of getting the BusyBox version, as that gets echoed to stderr.
This is the output:
Read the rest of this entry »
Posted in *nix, *nix-tools, cURL, ESXi6, ESXi6.5, ESXi6.7, Power User, Virtualization, VMware ESXi, wget | Leave a Comment »