Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retrieve list of IP Address from tnsnames.ora file.

Posted on 2007-11-20
9
Medium Priority
?
1,200 Views
Last Modified: 2008-02-01
Hi Experts,

I want to write a code in delphi to find out the existing IP addresses in the tnsnames.ora file.
How can it be done.

Thanks
0
Comment
Question by:Asmitagoyal
[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
  • 4
  • 4
9 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20326261
can you post the contents of the file you want to extract the ip's from?
0
 

Author Comment

by:Asmitagoyal
ID: 20326398
hi
the contents of the tnsnames.ora file are as under:

TEST1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 100.10.10.1)(PORT = 1111))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TestService)
    )
  )

TEST2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 100.10.10.2)(PORT = 1111))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TestService)
    )
  )

TEST3 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 100.10.10.3)(PORT = 1111))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TestService)
    )

These are the values stored in tnsnames.ora file. now through delphi code i want to get the list of all the IPs.
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 400 total points
ID: 20326455
see this working example
procedure CollectIPs(FileName: string; IPs: TStringList; IncludePortNumbers: boolean);
const HOST_SEP = 'HOST = ';
      PORT_SEP = 'PORT = ';
var Data: TStringList;
    i: integer;
    p: integer;
    IP, Port: string;
begin
 Data := TStringList.Create();
 
 try
  Data.LoadFromFile(FileName);
 
  for i := 0 to Data.Count - 1 do
  begin
   IP := '';
   Port := '';
 
   p := Pos(HOST_SEP, Data[i]);
 
   if p > 0 then
   begin
    IP := Copy(Data[i], p + Length(HOST_SEP), 255);
    IP := LeftStr(IP, Pos(')', IP) - 1);
 
    if IncludePortNumbers then
    begin
     p := Pos(PORT_SEP, Data[i]);
 
     if p > 0 then
     begin
      Port := ':' + Copy(Data[i], p + Length(PORT_SEP), 255);
      Port := LeftStr(Port, Pos(')', Port) - 1);
     end;
 
     if IP <> '' then
      IPs.Add(IP + Port);
    end;
   end;
 
  end;
 
 finally
  Data.Free();
 end;
end;
 
procedure TForm2.Button1Click(Sender: TObject);
var IPs: TStringList;
begin
 IPs := TStringList.Create();
 
 try
  CollectIPs('c:\tnsnames.ora', IPs, true);
  IPs.SaveToFile('c:\addresses.lst');
 finally
  IPs.Free();
 end;
end;

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Asmitagoyal
ID: 20326793
Hi
This has solved the problem.
In continuation with this i've another problem.
Suppose i'm connected to Test2 server. Now is there any way to find out the location of the tnsnames.ora file and then get the IP address of the corresponding server.

Thanks
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20327007
do you mean you want to know where the tnsnames.ora file is located, or how to find an ip for given server (Test2) in this tnsnames.ora file?
0
 

Author Comment

by:Asmitagoyal
ID: 20327167
hi
you have told the solution for getting the IP address but is there any way to find the location of tnsnames.ora other than hardcoding it.

Thanks
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20327179
I don't know where it is normally located. Do you have any information on this?
0
 
LVL 1

Assisted Solution

by:Metalnib
Metalnib earned 100 total points
ID: 20327798
It can be found in the ORACLE_HOME/network/admin directory on the client, usually.
echo %ORACLE_HOME%
Or it can be in any directory pointed by TNS_ADMIN
But if you use DBX connection with SID, oracle driver will find it for you.
0
 

Author Comment

by:Asmitagoyal
ID: 20338443
Hi
i want a delphi code which automatically finds out the file. Is there any way to find it out.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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