"Get host name and IP address" and "monitor computers in LAN"

Source: Internet
Author: User
"Get host name and IP address" and "monitor computers in LAN" Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiBase/html/delphi_20061209192223212.html
Which of the following prawns can help you? Program Thank you for analyzing this !!!!!!
Obtain the Host Name and IP Address:
Hostname;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
Stdctrls, Winsock;
Type
Tform1 = Class (tform)
Edit1: tedit; label1: tlabel; label2: tlabel; edit2: tedit; edit3: tedit;
Label3: tlabel; button1: tbutton;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
VaR
IP: string;
Ipstr: string;
Buffer: array [1 .. 32] of char;
I: integer;
Wsdata: twsadata;
HOST: phostent;
Begin
If wsastartup (2, wsdata) <> 0 then
Begin
Showmessage ('ws2 _ 32. dll initialization failed! '); Halt; end;
Try
If gethostname (@ buffer [1], 32) <> 0 then
Begin
Showmessage ('no host name is obtained! '); Halt; end;
Except
Showmessage ('host name not returned successfully '); halt; end;
HOST: = gethostbyname (@ buffer [1]);
If host = nil then
Begin
Showmessage ('IP address is blank '); halt; End
Else
Begin
Edit2.text: = host. h_name;
Edit3.text: = CHR (host. h_addrtype + 64 );
For I: = 1 to 4 do
Begin
IP: = inttostr (ord (host. h_addr ^ [I-1]);
Showmessage ('segment IP Address: '+ IP );
If I <4 then
Ipstr: = ipstr + IP + '.'
Else
Edit1.text: = ipstr + IP; end;
Wsacleanup; end.
Monitor computers in the LAN:
Unit local;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
Stdctrls, Winsock;
Type
Tform1 = Class (tform)
Button1: tbutton; edit1: tedit; memo1: tmemo; label1: tlabel;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Function findcomputer (computername: string): Boolean;
Implementation
{$ R *. DFM}
Function findcomputer (computername: string): Boolean;
VaR
Wsadata: twsadata;
Hostent: phostent;
Begin
Result: = true;
Wsastartup (2, wsadata );
Hostent: = gethostbyname (pchar (computername ));
If hostent = nil then result: = false;
Wsacleanup; end;
Procedure tform1.button1click (Sender: tobject );
Begin
If findcomputer (edit1.text) = true then
Memo1.lines. Add (edit1.text + 'on the LAN! ')
Else
Memo1.lines. Add (edit1.text + 'is not on the LAN! '); End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.