Skip to content
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
6 changes: 4 additions & 2 deletions docs/_docs/user-guide/eldritch.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ This function also supports globbing with `*` for example:
```python
file.list("/home/*/.bash_history") # List all files called .bash_history in sub dirs of `/home/`
file.list("/etc/*ssh*") # List the contents of all dirs that have `ssh` in the name and all files in etc with `ssh` in the name
file.list("\\\\127.0.0.1\\c$\\Windows\\*.yml") # List files over UNC paths
```

Each file is represented by a Dict type.
Expand Down Expand Up @@ -361,6 +362,7 @@ This function supports globbing with `*` for example:
```python
file.read("/home/*/.bash_history") # Read all files called .bash_history in sub dirs of `/home/`
file.read("/etc/*ssh*") # Read the contents of all files that have `ssh` in the name. Will error if a dir is found.
file.read("\\\\127.0.0.1\\c$\\Windows\\Temp\\metadata.yml") # Read file over Windows UNC
```

### file.remove
Expand All @@ -381,9 +383,9 @@ The <b>file.replace</b> method finds the first string matching a regex pattern i

The <b>file.replace_all</b> method finds all strings matching a regex pattern in the specified file and replaces them with the value. Please consult the [Rust Regex Docs](https://rust-lang-nursery.github.io/rust-cookbook/text/regex.html) for more information on pattern matching.

### file.tmp_file
### file.temp_file

`file.tmp_file(name: Option<str>) -> str`
`file.temp_file(name: Option<str>) -> str`

The <b> file.temp</b> method returns the path of a new temporary file with a random filename or the optional filename provided as an argument.

Expand Down
14 changes: 11 additions & 3 deletions tavern/tomes/netstat/main.eldritch
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def print_table(rows: list[list]):
row.append(rpad(c, counts[i]+2))
print("".join(row))


def netstat():
"""Pretty print the netstat results"""
# Faster to do this than to call process.info on each PID
Expand All @@ -22,7 +23,7 @@ def netstat():
pids[p['pid']] = p['name']

# Counts for dynamic column formating
counts = [6,6,7,6,8]
counts = [6, 6, 7, 6, 8]
rows = [["PROTO", "LOCAL", "REMOTE", "STATE", "PROCESS"]]
# Loop through each net result and format the columns
for n in process.netstat():
Expand All @@ -35,16 +36,23 @@ def netstat():
remote = n.get("remote_address", "")
if remote:
fields[2] = remote + ":" + str(n.get("remote_port",))
else:
fields[2] = "???"

# Established = ESTAB
if fields[3] == "ESTABLISHED":
fields[3] = fields[3][:5]
else:
fields[3] = "???"
# Get proc info. "pids" will only ever be one
if n["pids"]:
fields += ["["+str(n["pids"][0])+"]"+pids.get(n["pids"][0])]
if "pid" in n:
if n["pid"]:
fields += ["["+str(n["pid"])+"]"+pids.get(n["pid"])]

rows.append(fields)
print_table(rows)


time.sleep(1)

netstat()