A
Amarr
Hallo,
ich sitze zur Zeit an einem Schulprojekt und zwar muss ich einen IP und Portscanner in C++ programmieren.
Da meine Vorkenntnisse nicht so überragend sind hänge ich im Moment an einem Problem fest und weis einfach nicht mehr weiter.
Ich benutze zum Programmieren Eclipse IDE for C/C++ und MinGW, mein OS ist Windows7 32bit.
Mein Problem ist nun, dass ich obwohl libws2_32.a und libiphlpapi.a über den linker eingebunden sind immernoch die Fehlermeldung
workspace/win/Debug/../win.cpp:109: undefined reference to `IcmpCreateFile@0'
bekomme. Hier mal meinem Quellcode:
#include <windows.h>
#include <stdio.h>
#include <winsock2.h>
#include <io.h>
#include <string.h>
#include <iostream>
#include <iphlpapi.h>
#include <ipexport.h>
#include "icmpapi.h" // Da die icmpapi.h nicht dabei war habe ich sie von http://www.koders.com/c/fidB304BDC3036C040B5B1063271EC986BDC9957618.aspx?s=windows.h genommen.
using namespace std;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void IntToString(int i, char* buffer)
{
sprintf(buffer, "%d", i);
}
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szComLine, int iCmdShow){
char szName[] = "Fenster";
char szTitel[] = "ScanU";
int xPos = 0;
int yPos = 0;
int xSize = 600;
int ySize = 400;
HBRUSH bgColor = CreateSolidBrush(RGB(180,120,90));
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = bgColor;
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;
RegisterClass (&wc);
HWND hwnd = CreateWindow (szName, szTitel, WS_OVERLAPPEDWINDOW, xPos, yPos, xSize, ySize, NULL, NULL, hI, NULL);
HWND BCX_Listbox(char*,HWND,int,int,int,int,int,int=0,int=-1);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
MSG msg;
while(GetMessage (&msg, NULL, 0, 0)){
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
static HWND hwndButton1, hwndButton2, sIP, eIP, sPort, ePort, list1, list2;
char vIP[16], bIP[16];
struct sockaddr_in addr;
unsigned long start, end, temp;
HANDLE IcmpFile;
DWORD ReturnValue = 0;
char SendData[] = "Ping";
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
switch (message){
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
SetTextColor(hdc,RGB(0,0,0));
SetBkColor(hdc,RGB(180,120,90));
TextOut (hdc, 37, 10, "Start IP:", 9);
TextOut (hdc, 42, 30, "End IP:", 7);
TextOut (hdc, 400, 10, "Start Port:", 11);
TextOut (hdc, 405, 30, "End Port:", 9);
EndPaint (hwnd, &ps);
return (0);
case WM_CREATE:
hwndButton1 = CreateWindow ("button", "Netz Scannen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 250, 50, 100, 20, hwnd, (HMENU)1,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hwndButton2 = CreateWindow ("button", "Ports Scannen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 250, 180, 100, 20, hwnd, (HMENU)2,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
sIP = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 92,10,110,18, hwnd, (HMENU)3, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
eIP = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 92,30,110,18, hwnd, (HMENU)4, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
sPort = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 470,10,50,18, hwnd, (HMENU)5, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
ePort = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 470,30,50,18, hwnd, (HMENU)6, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
list1 = CreateWindow ("listbox", "",WS_CHILD | WS_VISIBLE | LBS_STANDARD, 30, 75, 200, 250, hwnd, (HMENU)7,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) , NULL);
list2 = CreateWindow ("listbox", "",WS_CHILD | WS_VISIBLE | LBS_STANDARD, 370, 75, 200, 250, hwnd, (HMENU)8,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) , NULL);
return (0);
case WM_COMMAND:
switch(LOWORD(wParam)){
case 1:
GetWindowText(sIP,vIP,16);
GetWindowText(eIP,bIP,16);
SendMessage(list1, LB_RESETCONTENT, 0, 0);
start = ntohl(inet_addr(vIP));
end = ntohl(inet_addr(bIP));
if (start > end){
temp = start;
start = end;
end = temp;
}
for(temp = start; temp <= end; temp++){
addr.sin_addr.s_addr = htonl(temp);
IcmpFile = IcmpCreateFile();
SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)inet_ntoa(addr.sin_addr));
}
break;
case 2:
break;
}
return(0);
case WM_DESTROY:
PostQuitMessage (0);
return (0);
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
Ich weis, das man das noch schöner gestallten könnte, aber es erfüllt seinen Zweck. Das Programm ist (soll) eigendlich ganz simpel sein, man gibt die erste und die letzte IP des zu scannenden Bereiches ein und er scannt alles was dazwischen ist und gibt die erreichten IPs in einer liste aus.
Zur Hilfe nehme ich http://msdn.microsoft.com/en-us/library/aa366050(VS.85).aspx aber ich bekomme dieses Problem im Moment nicht gelöst, ein Schulkollege meint es könnte an der library liegen.
Habt ihr vielleicht eine Idee wo der fehler ist?
ich sitze zur Zeit an einem Schulprojekt und zwar muss ich einen IP und Portscanner in C++ programmieren.
Da meine Vorkenntnisse nicht so überragend sind hänge ich im Moment an einem Problem fest und weis einfach nicht mehr weiter.
Ich benutze zum Programmieren Eclipse IDE for C/C++ und MinGW, mein OS ist Windows7 32bit.
Mein Problem ist nun, dass ich obwohl libws2_32.a und libiphlpapi.a über den linker eingebunden sind immernoch die Fehlermeldung
workspace/win/Debug/../win.cpp:109: undefined reference to `IcmpCreateFile@0'
bekomme. Hier mal meinem Quellcode:
#include <windows.h>
#include <stdio.h>
#include <winsock2.h>
#include <io.h>
#include <string.h>
#include <iostream>
#include <iphlpapi.h>
#include <ipexport.h>
#include "icmpapi.h" // Da die icmpapi.h nicht dabei war habe ich sie von http://www.koders.com/c/fidB304BDC3036C040B5B1063271EC986BDC9957618.aspx?s=windows.h genommen.
using namespace std;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void IntToString(int i, char* buffer)
{
sprintf(buffer, "%d", i);
}
int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szComLine, int iCmdShow){
char szName[] = "Fenster";
char szTitel[] = "ScanU";
int xPos = 0;
int yPos = 0;
int xSize = 600;
int ySize = 400;
HBRUSH bgColor = CreateSolidBrush(RGB(180,120,90));
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hI;
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = bgColor;
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;
RegisterClass (&wc);
HWND hwnd = CreateWindow (szName, szTitel, WS_OVERLAPPEDWINDOW, xPos, yPos, xSize, ySize, NULL, NULL, hI, NULL);
HWND BCX_Listbox(char*,HWND,int,int,int,int,int,int=0,int=-1);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
MSG msg;
while(GetMessage (&msg, NULL, 0, 0)){
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
static HWND hwndButton1, hwndButton2, sIP, eIP, sPort, ePort, list1, list2;
char vIP[16], bIP[16];
struct sockaddr_in addr;
unsigned long start, end, temp;
HANDLE IcmpFile;
DWORD ReturnValue = 0;
char SendData[] = "Ping";
LPVOID ReplyBuffer = NULL;
DWORD ReplySize = 0;
switch (message){
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
SetTextColor(hdc,RGB(0,0,0));
SetBkColor(hdc,RGB(180,120,90));
TextOut (hdc, 37, 10, "Start IP:", 9);
TextOut (hdc, 42, 30, "End IP:", 7);
TextOut (hdc, 400, 10, "Start Port:", 11);
TextOut (hdc, 405, 30, "End Port:", 9);
EndPaint (hwnd, &ps);
return (0);
case WM_CREATE:
hwndButton1 = CreateWindow ("button", "Netz Scannen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 250, 50, 100, 20, hwnd, (HMENU)1,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hwndButton2 = CreateWindow ("button", "Ports Scannen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 250, 180, 100, 20, hwnd, (HMENU)2,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
sIP = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 92,10,110,18, hwnd, (HMENU)3, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
eIP = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 92,30,110,18, hwnd, (HMENU)4, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
sPort = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 470,10,50,18, hwnd, (HMENU)5, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
ePort = CreateWindow("edit","",WS_CHILD | WS_VISIBLE, 470,30,50,18, hwnd, (HMENU)6, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
list1 = CreateWindow ("listbox", "",WS_CHILD | WS_VISIBLE | LBS_STANDARD, 30, 75, 200, 250, hwnd, (HMENU)7,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) , NULL);
list2 = CreateWindow ("listbox", "",WS_CHILD | WS_VISIBLE | LBS_STANDARD, 370, 75, 200, 250, hwnd, (HMENU)8,(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) , NULL);
return (0);
case WM_COMMAND:
switch(LOWORD(wParam)){
case 1:
GetWindowText(sIP,vIP,16);
GetWindowText(eIP,bIP,16);
SendMessage(list1, LB_RESETCONTENT, 0, 0);
start = ntohl(inet_addr(vIP));
end = ntohl(inet_addr(bIP));
if (start > end){
temp = start;
start = end;
end = temp;
}
for(temp = start; temp <= end; temp++){
addr.sin_addr.s_addr = htonl(temp);
IcmpFile = IcmpCreateFile();
SendMessage(list1, LB_ADDSTRING, NULL, (LPARAM)inet_ntoa(addr.sin_addr));
}
break;
case 2:
break;
}
return(0);
case WM_DESTROY:
PostQuitMessage (0);
return (0);
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
Ich weis, das man das noch schöner gestallten könnte, aber es erfüllt seinen Zweck. Das Programm ist (soll) eigendlich ganz simpel sein, man gibt die erste und die letzte IP des zu scannenden Bereiches ein und er scannt alles was dazwischen ist und gibt die erreichten IPs in einer liste aus.
Zur Hilfe nehme ich http://msdn.microsoft.com/en-us/library/aa366050(VS.85).aspx aber ich bekomme dieses Problem im Moment nicht gelöst, ein Schulkollege meint es könnte an der library liegen.
Habt ihr vielleicht eine Idee wo der fehler ist?