Home page logo
/
Zenmap screenshot
Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
Example Nmap output

Library stringaux

Auxiliary functions for string manipulation

Author:

  • Daniel Miller

Copyright© Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/stringaux.lua

Functions

filename_escape (s)

Escape a string to remove bytes and strings that may have meaning to a filesystem, such as slashes.

ipattern (pattern)

Returns the case insensitive pattern of given parameter

strjoin (delimiter, list)

Join a list of strings with a separator string.

strsplit (pattern, text)

Split a string at a given delimiter, which may be a pattern.



Functions

filename_escape (s)

Escape a string to remove bytes and strings that may have meaning to a filesystem, such as slashes.

All bytes are escaped, except for:

  • alphabetic a-z and A-Z
  • digits 0-9
  • . _ -
In addition, the strings "." and ".." have their characters escaped.

Bytes are escaped by a percent sign followed by the two-digit hexadecimal representation of the byte value.

  • filename_escape("filename.ext") --> "filename.ext"
  • filename_escape("input/output") --> "input%2foutput"
  • filename_escape(".") --> "%2e"
  • filename_escape("..") --> "%2e%2e"
This escaping is somewhat like that of JavaScript encodeURIComponent, except that fewer bytes are whitelisted, and it works on bytes, not Unicode characters or UTF-16 code points.

Parameters

  • s:
ipattern (pattern)

Returns the case insensitive pattern of given parameter

Useful while doing case insensitive pattern match using string library. https://stackoverflow.com/questions/11401890/case-insensitive-lua-pattern-matching/11402486#11402486

Parameters

  • pattern: The string

Usage:

stringaux.ipattern("user")
--> "[uU][sS][eE][rR]"

Return value:

A case insensitive patterned string
strjoin (delimiter, list)

Join a list of strings with a separator string.

This is Lua's table.concat function with the parameters swapped for coherence.

Parameters

  • delimiter: String to delimit each element of the list.
  • list: Array of strings to concatenate.

Usage:

stringaux.strjoin(", ", {"Anna", "Bob", "Charlie", "Dolores"})
--> "Anna, Bob, Charlie, Dolores"

Return value:

Concatenated string.
strsplit (pattern, text)

Split a string at a given delimiter, which may be a pattern.

If you want to loop over the resulting values, consider using string.gmatch instead.

Parameters

  • pattern: Pattern that separates the desired strings.
  • text: String to split.

Usage:

stringaux.strsplit(",%s*", "Anna, Bob, Charlie, Dolores")
--> { "Anna", "Bob", "Charlie", "Dolores" }

Return value:

Array of substrings without the separating pattern.

See also:

Nmap Site Navigation

Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]