Solved

Query to parse out the IP address from string

Posted on 2008-10-17
2
272 Views
Last Modified: 2012-05-05
Looking for a way in a SQL query to extract the IP address from a string and then rename it.
For example I have a date field called Date_Time and field called "message" and it contains data such as

TCP connection 72260 for Outside:123.123.123.19/4717 to Inside:0.0.0.0/650 duration 0:00:00 bytes 0 TCP Reset-I ()
TCP connection 7260 for Outside:123.123.129.145/4718 to Inside:10.10.10.10/60 duration 0:00:00 bytes 0 TCP Reset-I ()

I want to grab the IP address of 123.123.123.19 and return something like
Date_Time, Host
2008-10-17 10:48:48    NewHostName       <---- based on the IP of 123.123129.145
2008-10-17 10:50:17    AnotherHostName <---- based on the IP of 123.123123.19
0
Comment
Question by:edrz01
2 Comments
 
LVL 8

Expert Comment

by:srafi78
ID: 22742443
You might have to use the replace function for each each IP and replace it with the string you want to put in its palce.
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22743258
this will find the IP address in message along with date_time, but I'm not sure where you want to get the hostname from.

Just replace your table name with the derived table I have put sample data in for after the FROM
select date_time,substring(message, charindex('Outside:',message)+8,charindex('/',message,charindex('Outside:',message)+8)-(charindex('Outside:',message)+8))
 

from 

(select 'TCP connection 72260 for Outside:123.123.123.19/4717 to Inside:0.0.0.0/650 duration 0:00:00 bytes 0 TCP Reset-I ()' as Message

union select 'TCP connection 7260 for Outside:123.123.129.145/4718 to Inside:10.10.10.10/60 duration 0:00:00 bytes 0 TCP Reset-I ()'

) a

Open in new window

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now