| | |
Port Scanner in C++
Thread Solved
![]() |
•
•
Join Date: Oct 2006
Posts: 172
Reputation:
Solved Threads: 2
Hi all
I was looking for a port scanner to see what was open on my laptop and I thought as I was learning C++ why not search for a C++ port scanner. I came across this code I can make sense of most of it but it wont compile. I have linked the -lws2_32 file that I was told is needed because I use Dev, I looked in Project -> Project Options -> Parameters -> and i went to the little folder icon and searched for the library in the lib but it wasn't there is i just went to the "Linker" edit box and typed -lws2_32 but that didn't work either. Here is the code
These are the error messages I am getting on line 46 it has a comment underneath
C:\Dev-Cpp\port.cpp In function `int main()':
C:\Dev-Cpp\port.cpp [Warning] passing NULL used for non-pointer converting 3 of `int connect(SOCKET, const sockaddr*, int)'
[Linker error] undefined reference to `__cpu_features_init'
C:\Dev-Cpp\port.cpp ld returned 1 exit status
Can someone please explain what is wrong, I think it is because I am not linking that file correctly?
Cheers
HLA91
I was looking for a port scanner to see what was open on my laptop and I thought as I was learning C++ why not search for a C++ port scanner. I came across this code I can make sense of most of it but it wont compile. I have linked the -lws2_32 file that I was told is needed because I use Dev, I looked in Project -> Project Options -> Parameters -> and i went to the little folder icon and searched for the library in the lib but it wasn't there is i just went to the "Linker" edit box and typed -lws2_32 but that didn't work either. Here is the code
C++ Syntax (Toggle Plain Text)
/*-------------------- | if your using dev-c++ | you need to link | -lws2_32 | to your application ---------------------*/ #include <winsock2.h> #include <iostream> using namespace std; char IP[20]; int start, end, temp, err, nret; SOCKET sock; SOCKADDR_IN Info; WSADATA wsadata; int main() { err = WSAStartup(MAKEWORD(2, 2), &wsadata); if(err != 0) { cout << "Error with winsock. Will Now Exit." << endl; cin.get(); return 0; } cout << "Target IP: "; cin>>IP; cout << "Starting Port: "; cin>>start; cout << "End Port: "; cin>>end; cin.ignore(); cout << endl << endl << "Starting Scan..." << endl << endl; temp = start; while(temp < end) { sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); Info.sin_family = AF_INET; Info.sin_port = htons(start); nret = connect(sock, NULL, NULL); // error is for line above if(nret != SOCKET_ERROR) { cout << "Port " << temp << " - OPEN! " << endl; } temp++; closesocket(sock); } cout << endl << "Finished With Scan..." << endl; cin.get(); return 0; }
These are the error messages I am getting on line 46 it has a comment underneath
C:\Dev-Cpp\port.cpp In function `int main()':
C:\Dev-Cpp\port.cpp [Warning] passing NULL used for non-pointer converting 3 of `int connect(SOCKET, const sockaddr*, int)'
[Linker error] undefined reference to `__cpu_features_init'
C:\Dev-Cpp\port.cpp ld returned 1 exit status
Can someone please explain what is wrong, I think it is because I am not linking that file correctly?
Cheers
HLA91
![]() |
Similar Threads
- Regarding Online Port Scanner (IT Professionals' Lounge)
- Port Scanner Tutorials (Visual Basic 4 / 5 / 6)
- Port Scanner Reporting Zero Ports Opened. (Networking Hardware Configuration)
- Port scanner (C#)
- Can't install scanner (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: std: a namespace with this name does not exist
- Next Thread: max and min
| Thread Tools | Search this Thread |
anyfile api array based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download draw dynamic dynamiccharacterarray email encryption error file forms fstream function functions game gdi+ givemetehcodez gnu graph gui homeworkhelp homeworkhelper http iamthwee ibm ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output packing parameter pointer problem program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video visualc++ visualizationtoolkit win32 windows winsock word wordfrequency wxwidgets






