Postgres INET NTOA

From Observer GigaFlow Support | VIAVI Solutions Inc.
Revision as of 08:42, 29 August 2023 by Kevin Wilkie (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

To convert from an integer to an IP address

Add the following function to postgres

CREATE OR REPLACE FUNCTION kinetntoa(ip integer) RETURNS text AS $$
BEGIN
return  ((ip >> 24) & 255)|| '.' ||    ((ip >> 16) & 255)|| '.'  || ((ip >> 8) & 255) || '.' || (ip & 255);
END;
$$ LANGUAGE plpgsql;


Use as such

select kinetntoa(srcadd::int),kinetntoa(dstadd::int) from netflow limit 1000;