var
data: TWSAData;
sock: TSocket;
addr: TSockAddrIn;
iaddr: TInAddr;
i : Integer;
j,k : Integer;
begin
ListBox1.Clear;
j := StrToIntDef(Edit1.Text,1);
k := StrToIntDef(Edit2.Text,1);
for i := j to k do
begin
try
if (WSAStartup($0101, data) = 0) then
begin
sock := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock <> INVALID_SOCKET) then
begin
// zero out the addr struct.
FillChar(addr, SizeOf(TSockAddrIn), 0);
FillChar(iaddr, SizeOf(TInAddr), 0);
//fill in the internet address
iaddr.S_addr := inet_addr('210.108.212.5');
//fill in the rest of the address.
addr.sin_family := PF_INET;
addr.sin_port := htons(i);
addr.sin_addr := iaddr;
// try to connect, if it failes then the port is closed
if (connect(sock, addr, SizeOf(TSockAddrIn)) = 0) then
begin
ListBox1.Items.Add('Port ' + IntToStr(i) + ' IS open');
end else
begin
ListBox1.Items.Add('Port ' + IntToStr(i) + ' NOT open');
end;
end else
begin
ListBox1.Items.Add('There was an error creating the socket.');
end;
end
else
begin
ListBox1.Items.Add('Failed to initialize winsock.');
end;
ListBox1.Refresh;
finally
WSACleanup();
end;
end;
확인해보세요...
var
data: TWSAData;
sock: TSocket;
addr: TSockAddrIn;
iaddr: TInAddr;
i : Integer;
j,k : Integer;
begin
ListBox1.Clear;
j := StrToIntDef(Edit1.Text,1);
k := StrToIntDef(Edit2.Text,1);
for i := j to k do
begin
try
if (WSAStartup($0101, data) = 0) then
begin
sock := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock <> INVALID_SOCKET) then
begin
// zero out the addr struct.
FillChar(addr, SizeOf(TSockAddrIn), 0);
FillChar(iaddr, SizeOf(TInAddr), 0);
//fill in the internet address
iaddr.S_addr := inet_addr('210.108.212.5');
//fill in the rest of the address.
addr.sin_family := PF_INET;
addr.sin_port := htons(i);
addr.sin_addr := iaddr;
// try to connect, if it failes then the port is closed
if (connect(sock, addr, SizeOf(TSockAddrIn)) = 0) then
begin
ListBox1.Items.Add('Port ' + IntToStr(i) + ' IS open');
end else
begin
ListBox1.Items.Add('Port ' + IntToStr(i) + ' NOT open');
end;
end else
begin
ListBox1.Items.Add('There was an error creating the socket.');
end;
end
else
begin
ListBox1.Items.Add('Failed to initialize winsock.');
end;
ListBox1.Refresh;
finally
WSACleanup();
end;
end;