Solved

Query to parse out the IP address from string

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

730 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