Das ist ein Portscanner von mir, den ich irgendwann mal für Windows geschrieben hab. Daraus sollte für dich ersichtlich werden, wie man Raw-Sockets benutzt. Das steht aber auch alles auf
www.msdn.com
///////////////////////////////////////////////////////////////////////////////
// INCLUDES
///////////////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "stdlib.h"
#include "windows.h"
#include "winsock.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// DEFINES
///////////////////////////////////////////////////////////////////////////////
#define LPORT 130
#define HPORT 140
#define IPADDR "127.0.0.1"
#define PROGINFO "Mega Lame Portscanner 1.0 by Sewin"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// MAIN FUNCTION
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
// The Variables
int Count;
UINT Option;
WORD Version;
SOCKET Socket;
WSADATA WSAData;
SOCKADDR_IN Address;
// Show Program Info
printf("\n");
printf(PROGINFO);
printf("\n \n");
// Non-Unix Startup Routine
if (WSAStartup(MAKEWORD(2, 0), &WSAData) != 0)
{
printf("Error: Startup failed. \n");
return -1;
}
// Zero-Fill Address Struct
memset(&Address, 0, sizeof(SOCKADDR_IN));
// Set IPv4 Family
Address.sin_family=AF_INET;
// Set Destination IP-Address
Address.sin_addr.s_addr = inet_addr(IPADDR);
// Do from FirstPort to LastPort
for (Count = LPORT; Count < HPORT; Count++)
{
// Set actual Port
Address.sin_port = htons(Count);
// Socket Open
if ((Socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
printf("Error: Could not create Socket. \n");
return -1;
}
// Disable Socket Option SO_KEEPALIVE
Option = 0;
if (setsockopt(Socket, SOL_SOCKET, SO_KEEPALIVE, (char *) &Option, sizeof(Option)) != 0)
{
printf("Error: Could not set socket option. \n");
printf("%d", WSAGetLastError());
return -1;
}
// Enable Socket Option SO_DONTLINGER
Option = 1;
if (setsockopt(Socket, SOL_SOCKET, SO_DONTLINGER, (char *) &Option, sizeof(Option)) != 0)
{
printf("Error: Could not set socket option. \n");
printf("%d", WSAGetLastError());
return -1;
}
// Socket Connect
if (connect(Socket, (SOCKADDR*)&Address, sizeof(SOCKADDR)) != SOCKET_ERROR)
{
// Open Port
printf("%d", Count);
printf("\t open \n");
}
else
{
// Closed Port
printf("%d", Count);
printf("\t close \n");
}
// Socket Close
if (closesocket(Socket) != 0)
{
printf("Error: Could not close socket. \n");
return -1;
}
}
// Non-Unix Cleanup Routine
if (WSACleanup() != 0)
{
printf("Error: Cleanup failed. \n");
return -1;
}
// Exit
return 0;
}
///////////////////////////////////////////////////////////////////////////////