Hallo
habe mal ne kleine Frage. Evtl kennt hier jemand die antwort...
habe einen kleinen Portscanner geschrieben, der mir alle
SQL Server auflisten soll die in einer Range stehen. Ich übergebe der Function
IP und Port und erwarte ein True oder False (
SQL Server ist da bzw. nicht da) zurück.
Delphi-Quellcode:
Function ScanTCPPort(
IP, Port: DWORD): Boolean;
// Scans a specific TCP port and on a specific IP
var
//OPTON: DWORD;
TCPsock: TSocket;
A: TSockAddrIn;
NonBlocking: u_long;
Blocking: u_long;
TimeEval: TTimeVal;
rfds: TFDSet;
wfds: TFDSet;
retval: Integer;
IPAddy:
String;
WSAData: TWSAData;
begin
WSAStartup($11, WSAData);
result := False;
NonBlocking := 1;
Blocking := 0;
ZeroMemory(@A, sizeof(A));
A.sin_family := AF_INET;
A.sin_addr.S_addr := ntohl(
IP);
A.sin_port := htons(Port);
// Create/open a socket (stream, not datagram)
TCPsock := socket(AF_INET, SOCK_STREAM, 0);
If TCPsock <> INVALID_SOCKET
then begin
// Set socket options
{
OPTON := 0;
setsockopt(TCPsock, SOL_SOCKET, SO_KEEPALIVE, @OPTON, sizeof(OPTON));
setsockopt(TCPsock, SOL_SOCKET, SO_LINGER , @OPTON, sizeof(OPTON));
OPTON := 1;
setsockopt(TCPsock, SOL_SOCKET, SO_DONTLINGER, @OPTON, sizeof(OPTON));
// Only for compatibility with WinSock 1.1! It's default on newer versions.
setsockopt(TCPsock, IPPROTO_TCP, TCP_NODELAY, @OPTON, sizeof(OPTON));
}
IoctlSocket(TCPsock, FIONBIO, NonBlocking);
// Try to connect and return result
connect(TCPsock, A, sizeof(A));
FD_ZERO(rfds);
FD_SET(TCPsock, rfds);
wfds := rfds;
TimeEval.tv_sec := 0;
TimeEval.tv_usec := 1000000;
retval := select(TCPsock + 1, @rfds, @wfds,
nil, @TimeEval);
If retval = 1
then begin
result := True;
End;
End;
closesocket(TCPsock);
WSACleanup;
end;
Habe das ganze als NonBlocking umgebaut und habe nun das Problem das er die Socket nicht schließt sondern in einem
TCP mitschnitt steht folgendes:
socket (676) enabled its nonblocking mode
socket (676) connecting synchronously without blocking [name=24.118.103.248:1433]
socket (676) could not connect - WSAEWOULDBLOCK (A non-blocking socket operation could not be completed immediately)
socket (676) will be closed when outstanding asynchronous calls finish
socket (672) created [family=AF_INET, type=SOCK_STREAM, protocol=IPPROTO_IP, dwFlags=WSA_FLAG_OVERLAPPED]
socket (672) enabled its nonblocking mode
socket (672) connecting synchronously without blocking [name=24.118.103.249:1433]
socket (672) could not connect - WSAEWOULDBLOCK (A non-blocking socket operation could not be completed immediately)
socket (672) will be closed when outstanding asynchronous calls finish
socket (668) created [family=AF_INET, type=SOCK_STREAM, protocol=IPPROTO_IP, dwFlags=WSA_FLAG_OVERLAPPED]
socket (668) enabled its nonblocking mode
socket (668) connecting synchronously without blocking [name=24.118.103.250:1433]
socket (668) could not connect - WSAEWOULDBLOCK (A non-blocking socket operation could not be completed immediately)
socket (668) will be closed when outstanding asynchronous calls finish
Wie bekomme ich die Sockets geschlossen ?????? Suche mir schon einen Wolf bei Google und auch hier....
Habe mir diesen URSOURCE von dem
NoNVCL Scanner hier aus dem Board entliehen..... aber weis nun nicht mehr weiter....
[edit=Luckie]Delphi-Tags. Mfg, Luckie[/edit]