Eikonal Blog

2010.06.23

Memory of things disappearing > nmap stuff > getports.awk

Filed under: infosec — Tags: , — sandokan65 @ 10:50

Source: http://web.archive.org/web/20050114184017/http://www.synnergy.net/~rwx/nmap-xml-tools/getports.awk

Code:

#!/bin/awk -f 
# Lists open ports coming from nmap.
# It assumes the file is in PYX format and complies with the appropriate DTD.

function reset()
{
	protocol = "";
	portid = 0;
	state = ""
	service = "";
	in_port = 0;
}

BEGIN {
	reset();
}

/\(port$/ {
	in_port = 1;
}

/\)port$/ {
	printf("%s %u %s %s\n", protocol, portid, state, service);
	reset();
}

/^Aprotocol / {
	if (in_port)
		protocol = $2;
}

/^Aportid / {
	if (in_port)
		portid = $2;
}

/^Astate / {
	if (in_port)
		state = $2;
}

/^Aname / {
	if (in_port)
		service = $2;
}

Related here: AWK – https://eikonal.wordpress.com/2011/09/30/awk/

Create a free website or blog at WordPress.com.