
|
View Full Version : I need a program that pings a list of computer names...................
thomor25 07-15-2004, 04:52 PM I need a program that pings a list of computer names and outputs the names of ones that don't respond to a file.
Basically I have a list of computer names on our network. I want to add this list to the program, have it ping each name, if it doesn't respond the program will output the name to another file.
We have a domain with 6000 computer names in it and we want to be able to delete the computer names that don't exist anymore.
alex-info 07-15-2004, 04:56 PM Does it have to run on Linux or Windows ?
Do you want an application or a service ?
thomor25 07-15-2004, 06:58 PM windows, and an application
alex-info 07-15-2004, 10:55 PM I tried to code something that would solve your problem, here it is:
<<Removed/Please don't link to unknown .exe files>>
Save it (anywhere) and run it. Paste the list of computers to ping (either their machine name, IP or domain name) and then click GO.
Please tell me if you like it or if you'd like to have some things changed ...
Yup, coded specially for you :)
Wojjie 07-16-2004, 09:24 AM Perhaps give him the source instead of the EXE file?
alex-info 07-16-2004, 09:50 AM Not everybody has Delphi 5 installed on their machine...
If it makes anybody feel better I can post the source here, altought that would be pretty useless if you don't have Delphi...
If you feel unsafe about running an unknow exe file, I understand, please see this thread, I've written a program for this guy and he's pretty happy with it too..
http://www.webhostingtalk.com/showthread.php?s=&threadid=285338
If posting the source code makes you feel better, just tell me, I'll be morethan happy to do so.
alex-info 07-16-2004, 09:58 AM Sorry I see that my link has been removed, here's a new one to a zipped version, I hope this okay with the mods.
http://www.scripts.alex-info.net/misc/alexping/AlexPing.zip
I would like to see the source of this. It's been 2 or 3 month since I saw my last Delphi code.
Thanks
Matt ;)
DELPHI is such an awesome language.
thomor25 07-16-2004, 11:06 AM Yes can you please eith post the source code or pm it to me, i would highly appreciate it.
alex-info 07-16-2004, 11:07 AM Here the main procedure:
procedure TForm1.btnGOClick(Sender: TObject);
var
i: Integer;
InAddr : IPAddr;
IpAddr : String;
begin
pgbProgress.Min := 0;
pgbProgress.Max := lstComputers.Lines.Count;
pgbProgress.Step := 1;
lstSuccess.Lines.Clear;
lstFailure.Lines.Clear;
for i := 0 to lstComputers.Lines.Count-1 do
begin
if lstComputers.Lines[i] <> '' then
begin
lblStatus.Caption := 'Pinging '+lstComputers.Lines[i]+' ...';
Self.Update;
Application.ProcessMessages;
InAddr.S_un_b.s_b1 := 0;
InAddr.S_un_b.s_b2 := 0;
InAddr.S_un_b.s_b3 := 0;
InAddr.S_un_b.s_b4 := 0;
TranslateStringToTInAddr(lstComputers.Lines[i], InAddr);
IpAddr := IntToStr(InAddr.S_un_b.s_b1)+'.'+
IntToStr(InAddr.S_un_b.s_b2)+'.'+
IntToStr(InAddr.S_un_b.s_b3)+'.'+
IntToStr(InAddr.S_un_b.s_b4);
if (IpAddr <> '0.0.0.0') then
begin
if Ping(IpAddr) then
lstSuccess.Lines.Add(lstComputers.Lines[i])
else
lstFailure.Lines.Add(lstComputers.Lines[i]);
lstComputers.Lines[i] := lstComputers.Lines[i] + ' ( ' + IpAddr + ' )';
end else
begin
lstFailure.Lines.Add(lstComputers.Lines[i]);
lstComputers.Lines[i] := lstComputers.Lines[i] + ' ( no IP adress )';
end;
end;
pgbProgress.StepBy(1);
end;
lblStatus.Caption := 'Pinging completed.';
end;
And the unit named "UPing" (from the internet, not my code but works great)
unit UPing;
interface
uses
Windows, SysUtils, Classes;
type
TSunB = packed record
s_b1, s_b2, s_b3, s_b4: byte;
end;
TSunW = packed record
s_w1, s_w2: word;
end;
PIPAddr = ^TIPAddr;
TIPAddr = record
case integer of
0: (S_un_b: TSunB);
1: (S_un_w: TSunW);
2: (S_addr: longword);
end;
IPAddr = TIPAddr;
function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';
function IcmpCloseHandle (icmpHandle : THandle) : boolean;
stdcall; external 'icmp.dll'
function IcmpSendEcho
(IcmpHandle : THandle; DestinationAddress : IPAddr;
RequestData : Pointer; RequestSize : Smallint;
RequestOptions : pointer;
ReplyBuffer : Pointer;
ReplySize : DWORD;
Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';
function Ping(InetAddress : string) : boolean;
procedure TranslateStringToTInAddr(AIP: string; var AInAddr);
implementation
uses
WinSock;
function Fetch(var AInput: string;
const ADelim: string = ' ';
const ADelete: Boolean = true)
: string;
var
iPos: Integer;
begin
if ADelim = #0 then begin
// AnsiPos does not work with #0
iPos := Pos(ADelim, AInput);
end else begin
iPos := Pos(ADelim, AInput);
end;
if iPos = 0 then begin
Result := AInput;
if ADelete then begin
AInput := '';
end;
end else begin
result := Copy(AInput, 1, iPos - 1);
if ADelete then begin
Delete(AInput, 1, iPos + Length(ADelim) - 1);
end;
end;
end;
procedure TranslateStringToTInAddr(AIP: string; var AInAddr);
var
phe: PHostEnt;
pac: PChar;
GInitData: TWSAData;
begin
WSAStartup($101, GInitData);
try
phe := GetHostByName(PChar(AIP));
if Assigned(phe) then
begin
pac := phe^.h_addr_list^;
if Assigned(pac) then
begin
with TIPAddr(AInAddr).S_un_b do begin
s_b1 := Byte(pac[0]);
s_b2 := Byte(pac[1]);
s_b3 := Byte(pac[2]);
s_b4 := Byte(pac[3]);
end;
end
else
begin
raise Exception.Create('Error getting IP from HostName');
end;
end
else
begin
raise Exception.Create('Error getting HostName');
end;
except
FillChar(AInAddr, SizeOf(AInAddr), #0);
end;
WSACleanup;
end;
function Ping(InetAddress : string) : boolean;
var
Handle : THandle;
InAddr : IPAddr;
DW : DWORD;
rep : array[1..128] of byte;
begin
result := false;
Handle := IcmpCreateFile;
if Handle = INVALID_HANDLE_VALUE then
Exit;
TranslateStringToTInAddr(InetAddress, InAddr);
DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, 0);
Result := (DW <> 0);
IcmpCloseHandle(Handle);
end;
end.
alex-info 07-16-2004, 11:11 AM Originally posted by utsn
I would like to see the source of this. It's been 2 or 3 month since I saw my last Delphi code.
Thanks
Matt ;)
DELPHI is such an awesome language.
Yes, I love delphi too :)
Full (compilable) source code is available here:
http://www.scripts.alex-info.net/misc/alexping/AlexPing_src.zip
Out of the BOXe 07-18-2004, 06:54 PM wouldn't a ip scanner do the job??
Studio64 07-19-2004, 08:53 PM Originally posted by Out of the BOXe
wouldn't a ip scanner do the job??
Thats what I would do personally...
Angry IP Scanner is my personal fav. Just put in the whole range of all possible IP's in your company.
Another possibility would be to examine your DHCP leases. That would cover your dynamic computers and hopefully you have some management system for static IP's (QIP, etc). If you don't someone somewhere has a hell of a job w/ an excel spreadsheet :D
But, yes alex-info is a good coder, he actually fixed a bug for me in that program and gave me an updated version :D... (the thread he linked previously)
I wouldn't worry about his software that much. I havn't sandboxed a PC (the lab it's runs in is sandboxed anyhow) so I havn't done a full and thourough QA/QC to it but, I've never detected any abnormal behavior or abnormal net traffic resulting from it. So he's good in my book :D
thomor25 07-19-2004, 10:28 PM this program was for a government network with multiple subnets and ip ranges, it would take forever with an ip scanner and I would still have to compare to the host names in the domain since it is a very very large segmented network and I just want the 1 domains computers checked not all domains. Thank you alex your program was very helpful, 6000+ computers were scanned in exactly 8 hours, I now have a list of 2k that do exist, i'll just run the rest tomorrow.
deseek 07-19-2004, 11:02 PM theres a program called "grims ping" its actually intended to be used for scanning for anonymous ftp servers but can be set to just ping a rang or list of ips. its a very good free program and is multithreaded
|