?
Solved

Query to parse out the IP address from string

Posted on 2008-10-17
2
Medium Priority
?
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

777 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