Postgres INET NTOA

From Observer GigaFlow Support | VIAVI Solutions Inc.
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;