|
NAMErwpmaplookup - Map keys to prefix map entriesSYNOPSISrwpmaplookup { --map-file=MAP_FILE | --address-types[=MAP_FILE] | --country-codes[=MAP_FILE] } [--fields=FIELDS] [--ipset-files] [--no-errors] [--ip-format=FORMAT] [--integer-ips] [--zero-pad-ips] [--no-titles] [--no-columns] [--column-separator=CHAR] [--no-final-delimiter] [{--delimited | --delimited=CHAR}] [{--output-path=PATH | --pager=PAGER_PROG}] [--no-files ARG [ARGS...] | --xargs[=FILE] | FILE [FILES...]] rwpmaplookup --help rwpmaplookup --version DESCRIPTIONrwpmaplookup finds keys in a binary prefix map file and prints the key and its value in a textual, bar (|) delimited format.By default, rwpmaplookup expects its arguments to be the names of text files containing keys---one key per line. When the --ipset-files switch is given, rwpmaplookup takes IPset files as arguments and uses the IPs as the keys. The --no-files switch causes rwpmaplookup to treat each command line argument itself as a key to find in the prefix map. When --no-files is not specified, rwpmaplookup reads the keys from the files named on the command line or from the standard input when no file names are specified and neither --xargs nor --no-files is present. To read the standard input in addition to the named files, use "-" or "stdin" as a file name. When the --xargs switch is provided, rwpmaplookup reads the names of the files to process from the named text file or from the standard input if no file name argument is provided to the switch. The input to --xargs must contain one file name per line. You must tell rwpmaplookup the prefix map to use for look-ups using one of three switches:
If the --map-file switch specifies a prefix map containing protocol/port pairs, each input file should contain one protocol/port pair per line in the form PROTOCOL/PORT, where PROTOCOL is a number between 0 and 255 inclusive, and PORT is a number between 0 and 65535 inclusive. When the --ipset-files switch is specified, it is an error if the --map-file switch specifies a prefix map containing protocol/port pairs. When querying any other type of prefix map and the --ipset-files switch is not present, each textual input file should contain one IP address per line, where the IP is a single IP address (not a CIDR block) in canonical form or the integer representation of an IPv4 address. The --fields switch allows you to specify which columns appear in the output. The default columns are the key and the value, where the key is the IP address or protocol/port pair, and the value is the textual label for that key. If the prefix map contains IPv6 addresses, any IPv4 address in the input is mapped into the ::ffff:0:0/96 netblock when searching. If the prefix map contains IPv4 addresses only, any IPv6 address in the ::ffff:0:0/96 netblock is converted to IPv4 when searching. Any other IPv6 address is ignored, and it is not printed in the output unless the "input" field is requested. Prefix map files are created by the rwpmapbuild(1) and rwgeoip2ccmap(1) utilities. IPset files are created most often by rwset(1) and rwsetbuild(1). OPTIONSOption names may be abbreviated if the abbreviation is unique or is an exact match for an option. A parameter to an option may be specified as --arg=param or --arg param, though the first form is required for options that take optional parameters.One of --map-file, --address-types, or --country-codes is required.
The following arguments modify certain IP addresses prior to printing. These arguments may be combined with the above formats.
The following argument is also available:
EXAMPLESIn the following examples, the dollar sign ("$") represents the shell prompt. The text after the dollar sign represents the command line. Lines have been wrapped for improved readability, and the back slash ("\") is used to indicate a wrapped line.Country code examplesPrint the country code for a list of addresses read from the standard input.$ cat my-addrs.txt 128.2.0.0 128.2.0.1 $ cat my-addrs.txt | rwpmaplookup --country-codes key| value| 128.2.0.0| us| 128.2.0.1| us| Use --no-files to list the address on the command line. $ rwpmaplookup --country-codes 128.2.0.0 128.2.0.1 key| value| 128.2.0.0| us| 128.2.0.1| us| Use --ipset-files to read the addresses from an IPset file. $ rwsetbuild my-addrs.txt my-addrs.set $ rwpmaplookup --country-codes --ipset-files my-addrs.set key| value| 128.2.0.0| us| 128.2.0.1| us| Use the --fields switch to control which columns are printed. $ rwpmaplookup --country-codes --fields=value my-addrs.txt value| us| us| Add the --delimited and --no-titles switches so the output only contains the value column. Print the country code for a single address using the default country code prefix map. $ rwpmaplookup --country-codes --fields=value --delimited \ --no-titles --no-files 128.2.0.0 us Alternatively $ echo 128.2.0.0 \ | rwpmaplookup --country-codes --fields=value --delim --no-title us To use a different country code mapping file, provide that file as the argument to the --country-codes switch. $ rwpmaplookup --country-code=old-address-map.pmap --no-files 128.2.0.0 key|value| 128.2.0.0| us| CIDR block inputNote that rwpmaplookup does not parse text that contains CIDR blocks.$ echo '128.2.0.0/31' \ | rwpmaplookup --country-codes key|value| rwpmaplookup: Invalid IP '128.2.0.1/31' at -:1: Extra text follows value For this case, use the IPset tool rwsetbuild(1) to parse the CIDR block list and create a binary IPset stream, and pipe the IPset to rwpmaplookup. $ echo '128.2.0.0/31' \ | rwsetbuild \ | rwpmaplookup --country-code --ipset-files key|value| 128.2.0.0| --| 128.2.0.1| --| For versions of rwpmaplookup that do not have the --ipset-files switch, you can have rwsetcat(1) read the binary IPset stream and print the IP addresses as text, and pipe that into rwpmaplookup. Be sure to include the "--cidr-blocks=0" switch to rwsetcat which forces individual IP addresses to be printed. $ echo '128.2.0.0/31' \ | rwsetbuild \ | rwsetcat --cidr-blocks=0 \ | rwpmaplookup --country-code key|value| 128.2.0.0| --| 128.2.0.1| --| General prefix map usageConsider a user-defined prefix map, assigned-slash-8s.pmap, that maps each /8 in the IPv4 address space to its assignment.$ rwpmapcat assigned-slash-8s.pmap | head -4 ipBlock| label| 0.0.0.0/8| IANA - Local Identification| 1.0.0.0/8| APNIC| 2.0.0.0/8| RIPE NCC| Use the --map-file switch to map from IPs to labels using this prefix map. $ cat my-addrs.txt 17.17.17.17 9.9.9.9 $ cat my-addrs.txt | rwpmaplookup --map-file=assigned-slash-8s.pmap key| value| 17.17.17.17| Apple Computer Inc.| 9.9.9.9| IBM| Use --ip-format=decimal to print the output as integers. $ cat my-addrs.txt \ | rwpmaplookup --ip-format=decimal --map-file=assigned-slash-8s.pmap key| value| 286331153| Apple Computer Inc.| 151587081| IBM| Add the "input" field to see the input as well. $ cat my-addrs.txt \ | rwpmaplookup --ip-format=decimal --fields=key,value,input \ --map-file=assigned-slash-8s.pmap key| value| input| 286331153| Apple Computer Inc.| 17.17.17.17| 151587081| IBM| 9.9.9.9| Combine the "input" field with the --no-errors switch to see a row for each key. $ rwpmaplookup --fields=key,value,input --no-errors --no-files \ --map-file=assigned-slash-8s.pmap 9.9.9.9 17.1717.17 key| value| input| 9.9.9.9| Apple Computer Inc.| 9.9.9.9| | | 17.1717.17| The input can contain integer values. $ echo 151587081 \ | rwpmaplookup --fields=key,value,input --delimited=, \ --map-file=assigned-slash-8s.pmap key,value,input 9.9.9.9,IBM,151587081 Block outputSpecifying "block" in the --fields switch causes rwpmaplookup to print the CIDR block that contains the address key.$ cat my-addrs.txt 9.8.7.6 9.10.11.12 17.16.15.14 17.18.19.20 $ rwpmaplookup --map-file=assigned-slash-8s.pmap \ --fields=key,value,block my-addrs.txt key| value| block| 9.8.7.6| IBM| 9.0.0.0/8| 9.10.11.12| IBM| 9.0.0.0/8| 17.16.15.14| Apple Computer Inc.| 17.0.0.0/8| 17.18.19.20| Apple Computer Inc.| 17.0.0.0/8| To break the CIDR block into its starting and ending value, specify the "start-block" and "end-block" fields. $ rwpmaplookup --map-file=assigned-slash-8s.pmap \ --fields=key,value,start-block,end-block my-addrs.txt key| value| start-block| end-block| 9.8.7.6| IBM| 9.0.0.0| 9.255.255.255| 9.10.11.12| IBM| 9.0.0.0| 9.255.255.255| 17.16.15.14| Apple Computer Inc.| 17.0.0.0| 17.255.255.255| 17.18.19.20| Apple Computer Inc.| 17.0.0.0| 17.255.255.255| To get a unique list of blocks for the input keys, do not output the "key" field and pipe the output of rwpmaplookup to the uniq(1) command. (This works as long as the input data is sorted). $ cat my-addrs.txt \ | rwpmaplookup --map-file=assigned-slash-8s.pmap \ --fields=block,value \ | uniq block| value| 9.0.0.0/8| IBM| 17.0.0.0/8| Apple Computer Inc.| The values printed in the "block" column corresponds to the CIDR block that were used when the prefix map file was created. $ rwpmaplookup --map=assigned-slash-8s.pmap --fields=block,value \ --no-files 128.2.0.1 129.0.0.1 block| value| 128.0.0.0/8|Administered by ARIN| 129.0.0.0/8|Administered by ARIN| In the output from rwpmapcat(1), those two blocks are combined into a larger range. $ rwpmapcat --map=assigned-slash-8s.pmap | grep 128 128.0.0.0/6|Administered by ARIN| Working with IPsetsAssume you have a binary IPset file, my-ips.set, that has the contents shown here, and you want to find the list of unique assignments from the assigned-slash-8s.pmap file.$ rwsetcat --cidr-blocks=1 my-ips.set 9.9.9.0/24 13.13.13.0/24 15.15.15.0/24 16.16.16.0/24 17.17.17.0/24 18.18.18.0/24 Since the blocks in the assigned-slash-8s.pmap file are /8, use the rwsettool(1) command to mask the IPs in the IPset to the unique /8 that contains each of the IPs. $ rwsettool --mask=8 my-ips.set \ | rwpmaplookup --map-file=assigned-slash-8s.pmap key| value| 9.0.0.0| IBM| 13.0.0.0| Xerox Corporation| 15.0.0.0| Hewlett-Packard Company| 16.0.0.0|Digital Equipment Corporation| 17.0.0.0| Apple Computer Inc.| 18.0.0.0| MIT| Protocol/port prefix mapsAssume the service.pmap prefix map file maps protocol/port pairs to the name of the service running on the named port.$ rwpmapcat service.pmap startPair| endPair| label| 0/0| 0/65535| unknown| 1/0| 1/65535| ICMP| 2/0| 5/65535| unknown| 6/0| 6/21| TCP| 6/22| 6/22| TCP/SSH| ... 17/0| 17/52| UDP| 17/53| 17/53| UDP/DNS| ... To query this prefix map, the input must contain two numbers separated by a slash. $ rwpmaplookup --map-file=service.pmap --no-files 6/80 key| value| 6/80| TCP/HTTP| Specifying "block", "start-block", and "end-block" in the --fields switch also works for Protocol/port prefix map files. The "block" column contains the same information as the "start-block" and "end-block" columns separated by a single space. $ rwpmaplookup --map-file=service.pmap --no-files \ --fields=key,value,start,end,block \ 6/80 6/6000 17/0 17/53 128/128 key| value|start-blo|end-block| block| 6/80| TCP/HTTP| 6/80| 6/80| 6/80 6/80| 6/6000| TCP| 6/4096| 6/6143| 6/4096 6/6143| 17/0| UDP| 17/0| 17/31| 17/0 17/31| 17/53| UDP/DNS| 17/53| 17/53| 17/53 17/53| 200/200|Unassigned| 192/0|223/65535| 192/0 223/65535| Using the pmapfilter(3) plug-in to rwcut(1), you can print the label for the source port and destination port in the SiLK Flow file data.rw. $ rwcut --pmap-file=service.pmap --num-rec=5 \ --fields=proto,sport,src-service,dport,dst-service data.rw pro|sPort|src-service|dPort|dst-service| 17|29617| UDP| 53| UDP/DNS| 17| 53| UDP/DNS|29617| UDP| 6|29618| TCP| 22| TCP/SSH| 6| 22| TCP/SSH|29618| TCP| 1| 0| ICMP| 771| ICMP| The pmapfilter plug-in does not provide a way to print the values based on the application field. You can get that information by having rwcut print the protocol and application separated by a slash, and pipe the result into rwpmaplookup. $ rwcut --fields=proto,application --num-rec=5 \ --delimited=/ --no-title \ | rwpmaplookup --map-file=service.pmap key| value| 17/53| UDP/DNS| 17/53| UDP/DNS| 6/22| TCP/SSH| 6/22| TCP/SSH| 1/0| ICMP| ENVIRONMENT
FILES
NOTESrwpmaplookup was added in SiLK 3.0.rwpmaplookup duplicates the functionality of rwip2cc(1). rwip2cc is deprecated, and it will be removed in the SiLK 4.0 release. Examples of using rwpmaplookup in place of rwip2cc are provided in the latter's manual page. SEE ALSOrwpmapbuild(1), rwpmapcat(1), ccfilter(3), addrtype(3), pmapfilter(3), rwgeoip2ccmap(1), rwcut(1), rwset(1), rwsetbuild(1), rwsetcat(1), rwsettool(1), silk(7), uniq(1)
Visit the GSP FreeBSD Man Page Interface. |