Ethical Hacking

Learn to find vulnerabilities before the bad guys do! Gain real world hands on hacking experience in our state of the art hacking lab. Course designed and taught by expert instructors with years of penetration testing experience. 12 student maximum in every class. Certification attempt included in every package.
Computer Forensics Training at InfoSec Institute

Gain the in-demand skills of a certified computer examiner, learn to recover trace data left behind by fraud, theft, and cybercrime perpetrators. Discover the source of computer crime and abuse at your organization so that it never happens again. All of our class sizes are guaranteed to be 12 students or less to facilitate one-on-one interaction with one of our expert instructors.




Network Security Focus-Microsoft
[Top] [All Lists]

SQL scalar function to convert big int to dot notation

Subject: SQL scalar function to convert big int to dot notation
Date: Wed, 16 Jan 2008 12:19:21 -0800
For those of you logging ISA (or whatever) to SQL, you'll have no doubt
noted that the source and destination IP's are logged as long integers,
and not dot notation.   While this is great for anyone using geo-ip data
for reporting (as in using "between" logic in your queries) it's not
human readable.

For convenience, I've coded up a little scalar function for SQL in order
for you to easily convert the long int IP to dot notation for anyone
interested.  Once the function is created, you can simply do a "Select
blah, blah, blah, dbo.ConvertLongIP(IntSourceIPHere),
dbo.ConvertLongIP(IntDestinationIPHere)  from logs where whatever =
whatever" to return the dot notation IP. 

The SQL to create the function is included below.

Thanks.
t





set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:              Thor
-- Create date: 11/28/07
-- Description: Scalar function to converts long/bigint formatted IP
addresses to dot notation
-- =============================================
ALTER FUNCTION [dbo].[ConvertLongIP] 
(
        -- Add the parameters for the function here
        @LongIP bigint
)
RETURNS varchar(15)
AS
BEGIN

DECLARE @DotIP varchar(15),
                @bin varbinary(4)
 select @bin = cast(@LongIP as varbinary(4))
 select @DotIP = cast(convert(int,substring(@bin,1,1)) as varchar(3)) +
'.' 
 + cast(convert(int,substring(@bin,2,1)) as varchar(3)) + '.' 
 + cast(convert(int,substring(@bin,3,1)) as varchar(3)) + '.' 
 + cast(convert(int,substring(@bin,4,1)) as varchar(3))

RETURN @DotIP

END

<Prev in Thread] Current Thread [Next in Thread>
  • SQL scalar function to convert big int to dot notation, Thor (Hammer of God) <=