Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

My IP

Posted on 1999-06-28
8
Medium Priority
?
273 Views
Last Modified: 2010-04-06
How can I read my IP address from Delphi application? Please send me source code. Thakn's
0
Comment
Question by:mmilan
[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
8 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 40 total points
ID: 1384999
hi there ,
here is a solution just remember to add winsock to the uses section
Regards Barry

procedure TForm1.Button1Click(Sender: TObject);
  { add to uses "winsock" }
var
  wVersionRequested : WORD;
  wsaData : TWSAData;
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : pchar;
  OutPut:array[0..100] of char;
begin
{Start up WinSock}
     wVersionRequested := MAKEWORD(1, 1);
     WSAStartup(wVersionRequested, wsaData);

{Get the computer name}
     GetHostName(@s, 128);
     p := GetHostByName(@s);

{Get the IpAddress}
     p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
     WSACleanup;
 edit1.text:=StrPCopy(OutPut,'Hostname: '+Format('%s', [p^.h_Name]));
edit2.text:=StrPCopy(OutPut, 'IPaddress: '+Format('%s',[p2]));

end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 1385000
btw ,
if you have wsocket of f.piette and are on a network you can do this:

var
    IPList : TStrings;
    I      : Integer;
begin
    IPList := WSocket1.LocalIPList;
     for I := 0 to IPList.Count - 1 do
     Memo1.Lines.Add(IPList.Strings[I]);
end;

to get all ip addresses.
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385001
This code works if the machine is Win9x with DNS disabled?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:Radler
ID: 1385002
Idem to DNS enabled and HostName invalid?
0
 
LVL 17

Expert Comment

by:inthe
ID: 1385003

To Radler
hi ya
>>This code works if the machine is Win9x with DNS >>disabled?

which code do you mean?
the answer code or the f.piette code.?
did you get a error ?
i never tried with dns disabled,how you do that?
i used several times,several pc's with no troubles
.
hostname invalid?
where did this appear ?
in the editbox?
Regards
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385004
Yes, with f.piete I received a invalid hostname.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1385005
procedure TForm1.Button2Click(Sender: TObject);
var
    IPList : TStrings;
    I      : Integer;
begin
    IPList := WSocket.LocalIPList;
     for I := 0 to IPList.Count - 1 do
     Memo1.Lines.Add(IPList.Strings[I]);
end;

works with no problem for me.
are you sure it is using the wsocket of f.piette of another wsocket/
i have 3 wsocket.pas files  with different components and all are different files /sizes diffferent etc.

the best place to ask about this error is on francois's web site where he has a support mailing list and will help you with the problem.,he will be able to give the answer straight away im sure.

http://www.rtfm.be/fpiette/supportuk.htm
0
 
LVL 4

Expert Comment

by:Radler
ID: 1385006
Revised the situation
I found that DNS is enabled, but HostName and/or Domain are/is blank(s)
thanks by your attention.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

721 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