Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trip / trippy (network utility) #663

Merged
merged 6 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions _webi/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ __install_webi() {
#WEBI_PKG=
#WEBI_HOST=https://webinstall.dev
export WEBI_HOST

if test -z "$WEBI_WELCOME"; then
echo ""
printf "Thanks for using webi to install '\e[32m%s\e[0m' on '\e[33m%s/%s\e[0m'.\n" "${WEBI_PKG-}" "$(uname -s)/$(uname -r)" "$(uname -m)"
echo "Have a problem? Experience a bug? Please let us know:"
printf " \e[2m\e[36mhttps://github.com/webinstall/webi-installers/issues\e[0m\n"
echo ""
printf "\e[35mLovin'\e[0m it? Say thanks with a \e[1m\e[33mStar on GitHub\e[0m:\n"
printf " \e[36mhttps://github.com/webinstall/webi-installers\e[0m\n"
echo ""
echo ""
printf "Thanks for using webi to install '\e[32m%s\e[0m' on '\e[33m%s/%s\e[0m'.\n" "${WEBI_PKG-}" "$(uname -s)/$(uname -r)" "$(uname -m)"
echo "Have a problem? Experience a bug? Please let us know:"
printf " \e[2m\e[36mhttps://github.com/webinstall/webi-installers/issues\e[0m\n"
echo ""
printf "\e[35mLovin'\e[0m it? Say thanks with a \e[1m\e[33mStar on GitHub\e[0m:\n"
printf " \e[36mhttps://github.com/webinstall/webi-installers\e[0m\n"
echo ""
fi

WEBI_WELCOME=true
Expand Down
2 changes: 1 addition & 1 deletion sudo/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Write-Output "Installing sudo.cmd..."

# Couldn't figure out how to get this to work with "here strings", so forgive the ugly, but at least it works
Set-Content -Path .local\bin\sudo.cmd -Value "@echo off`r`npowershell -Command ""Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*'""`r`n@echo on"
Set-Content -Path "$Env:USERPROFILE\.local\bin\sudo.cmd" -Value "@echo off`r`npowershell -Command ""Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*'""`r`n@echo on"

Write-Output "Installed to '$Env:USERPROFILE\.local\bin\sudo.cmd'"
Write-Output ""
107 changes: 107 additions & 0 deletions trip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Trippy
homepage: https://github.com/fujiapple852/trippy
tagline: |
Trippy: A tool that combines the functionality of traceroute and ping designed for networking issue analysis.
---

To update or switch versions, run `webi trip@stable` (or `@v0.8`, `@beta`, etc).

## Cheat Sheet

> Trippy combines the functionality of `traceroute` and `ping` to assist in
> analyzing networking issues. It supports multiple protocols such as ICMP, UDP,
> and TCP, and is equipped with a Tui interface for detailed analysis.

```sh
sudo env PATH="$PATH" trip example.com
```

![](https://github.com/fujiapple852/trippy/blob/0.8.0/assets/0.8.0/hop_details.png?raw=true)

## Table of Contents

- Files
- Granting Root
- Tracing Protocols
- Tracing Options
- GoeIP Map

### Files

These are the files / directories that are created and/or modified with this
install:

```text
~/.config/trippy.toml
~/.local/bin/trip
<PROJECT-DIR>/.trippy.toml

# Windows
~/.local/bin/sudo.cmd
/Windows/System32/vcruntime140.dll (msvc runtime)
```

### How to Always Run as Root

Due to the nature of raw network access, `trip` always needs to run with
elevated network privileges.

On Linux `setcap` can be used to limit its root privileges to the network only.
On other systems it may need full root access.

**Linux**

```sh
trip_bin="$( readlink -f "$( command -v trip )" )"

sudo setcap 'CAP_NET_RAW+p' "${trip_bin}"
```

**macOS**

```sh
trip_bin="$( command -v trip )"

sudo chown root "${trip_bin}" && \
sudo chmod +s "${trip_bin}"
```

**Windows**

1. You need to add a firewall rule to allow ICMP
```pwsh
New-NetFirewallRule -DisplayName "ICMP Trippy Allow" -Name ICMP_TRIPPY_ALLOW -Protocol ICMPv4 -Action Allow
```
2. You'll need to run with an Administrator shell, or `sudo.cmd` **every time**:
```sh
sudo.cmd trip.exe example.com
```

### How to Trace with Various Protocols

You can use `icmp`, `tcp`, or `udp`:

```sh
trip --protocol icmp example.com
```

### How to set Tracing Options

You can pick a payload byte pattern (0-255) and packet size:

```sh
trip --packet-size 64 --payload-pattern 255
```

### How to View GeoIP Mapping

You'll need to download a geoip map database, such as this:

- <https://dev.maxmind.com/geoip/geolite2-free-geolocation-data>

```sh
trip example.com --geoip-mmdb-file ./GeoLite2-City.mmdb --tui-geoip-mode long
```

![](https://github.com/fujiapple852/trippy/raw/0.8.0/assets/0.8.0/world_map.png)
88 changes: 88 additions & 0 deletions trip/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env pwsh

##################
# Install trippy #
##################

# Every package should define these variables
$pkg_cmd_name = "trip"

$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\trip.exe"
$pkg_dst_bin = "$Env:USERPROFILE\.local\bin"
$pkg_dst = "$pkg_dst_bin"

$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\trippy-v$Env:WEBI_VERSION\bin\trip.exe"
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\trippy-v$Env:WEBI_VERSION\bin"
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\trippy-v$Env:WEBI_VERSION"
$pkg_src = "$pkg_src_cmd"

New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | Out-Null
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"

# Fetch MSVC Runtime
Write-Output "Checking for MSVC Runtime..."
IF (-not (Test-Path "\Windows\System32\vcruntime140.dll")) {
& "$Env:USERPROFILE\.local\bin\webi-pwsh.ps1" vcruntime
}

# Fetch sudo Runtime
Write-Output "Checking for sudo.cmd..."
IF (-not (Test-Path "$Env:USERPROFILE\.local\bin\sudo.cmd")) {
Set-Content -Path "$Env:USERPROFILE\.local\bin\sudo.cmd" -Value "@echo off`r`npowershell -Command ""Start-Process cmd -Verb RunAs -ArgumentList '/c cd /d %CD% && %*'""`r`n@echo on"
}

# Fetch archive
IF (!(Test-Path -Path "$pkg_download")) {
Write-Output "Downloading trippy from $Env:WEBI_PKG_URL to $pkg_download"
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
& Move-Item "$pkg_download.part" "$pkg_download"
}

IF (!(Test-Path -Path "$pkg_src_cmd")) {
Write-Output "Installing trippy"

# TODO: create package-specific temp directory
# Enter tmp
Push-Location .local\tmp

# Remove any leftover tmp cruft
Remove-Item -Path ".\trippy-v*" -Recurse -ErrorAction Ignore
Remove-Item -Path ".\trip.exe" -Recurse -ErrorAction Ignore

# NOTE: DELETE THIS COMMENT IF NOT USED
# Move single binary into root of temporary folder
#& move "$pkg_download" "trippy.exe"

# Unpack archive file into this temporary directory
# Windows BSD-tar handles zip. Imagine that.
Write-Output "Unpacking $pkg_download"
& tar xf "$pkg_download"

# Settle unpacked archive into place
Write-Output "Install Location: $pkg_src_cmd"
New-Item "$pkg_src_bin" -ItemType Directory -Force | Out-Null
Move-Item -Path ".\trippy-*\trip.exe" -Destination "$pkg_src_bin"

# Exit tmp
Pop-Location
}

Write-Output "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | Out-Null
New-Item "$pkg_dst_bin" -ItemType Directory -Force | Out-Null
Copy-Item -Path "$pkg_src_cmd" -Destination "$pkg_dst_cmd" -Recurse

Write-Output "IMPORTANT"
Write-Output ""
Write-Output " 1. Open PowerShell as Administrator"
Write-Output ""
Write-Output " sudo.cmd powershell"
Write-Output ""
Write-Output " 2. As Administrator, set a firewall rule to allow ICMP"
Write-Output ""
Write-Output " New-NetFirewallRule -DisplayName ""ICMP Trippy Allow"" -Name ICMP_TRIPPY_ALLOW -Protocol ICMPv4 -Action Allow"
Write-Output ""
Write-Output " 3. Run with sudo.cmd (or an Administrator shell)"
Write-Output ""
Write-Output " sudo.cmd trip.exe example.com"
Write-Output ""
46 changes: 46 additions & 0 deletions trip/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# shellcheck disable=SC2034
# "'pkg_cmd_name' appears unused. Verify it or export it."

__init_trip() {
set -e
set -u

################
# Install trip #
################

# Every package should define these 6 variables
pkg_cmd_name="trip"

pkg_dst_cmd="$HOME/.local/bin/trip"
pkg_dst="$pkg_dst_cmd"

pkg_src_cmd="$HOME/.local/opt/trippy-v$WEBI_VERSION/bin/trip"
pkg_src_dir="$HOME/.local/opt/trippy-v$WEBI_VERSION"
pkg_src="$pkg_src_cmd"

# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/trippy-v0.8.0/bin
mkdir -p "$(dirname "${pkg_src_cmd}")"

# mv ./trippy-*/trip ~/.local/opt/trippy-v0.8.0/bin/trip
mv ./trippy-*/trip "${pkg_src_cmd}"
}

# pkg_get_current_version is recommended, but not required
pkg_get_current_version() {
# 'trip -V' has output in this format:
# trip 0.8.0
# This trims it down to just the version number:
# 0.8.0
trip -V 2> /dev/null |
head -n 1 |
cut -d ' ' -f 2
}

}

__init_trip
20 changes: 20 additions & 0 deletions trip/releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var github = require('../_common/github.js');
var owner = 'fujiapple852';
var repo = 'trippy';

module.exports = function (request) {
return github(request, owner, repo).then(function (all) {
return all;
});
};

if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
// just select the first 5 for demonstration
all.releases = all.releases.slice(0, 5);
console.info(JSON.stringify(all, null, 2));
});
}
11 changes: 11 additions & 0 deletions trippy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: trippy (trip alias)
homepage: https://webinstall.dev/trip
tagline: |
Alias for https://webinstall.dev/trip
alias: trip
description: |
See https://webinstall.dev/trip
---

Alias for https://webinstall.dev/trip
5 changes: 5 additions & 0 deletions trippy/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/pwsh

Write-Output "'trippy@$Env:WEBI_TAG' is an alias for 'trip@$Env:WEBI_VERSION'"
IF ($null -eq $Env:WEBI_HOST -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
curl.exe -fsSL "$Env:WEBI_HOST/trip@$Env:WEBI_VERSION" | powershell
11 changes: 11 additions & 0 deletions trippy/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
set -u

__redirect_alias_trip() {
echo "'trippy@${WEBI_TAG:-stable}' is an alias for 'trip@${WEBI_VERSION-}'"
WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
curl -fsSL "$WEBI_HOST/trip@${WEBI_VERSION-}" | sh
}

__redirect_alias_trip