Solved

Query to parse out the IP address from string

Posted on 2008-10-17
2
303 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how the fundamental information of how to create a table.

840 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