EL_MPR
یک شنبه 10 خرداد 1394, 16:48 عصر
با سلام
یه برنامه پورت اسکنر نوشتم که یک آی پی می گیره و برای یک رنج پورت اون رو بررسی می کنه که باز هست یا بسته ولی می خوام که یک رنج آی پی بگیره و بعد این بررسی رو انجام بده ....مثلا یه آی پی شروع و یه آی پی پایان بگیره و بعد شماره آی پی رو تو حلقه افزایش بده کسی میدونه باید چی کار کنم؟؟؟؟
در واقع برای گرفتن یک رنج آی پی چه پیشنهادی دارید؟
#include <iostream>
#include <winsock2.h>//definitions to be used with the WinSock 2 DLL and WinSock 2 applications This header file corresponds to version 2.2.x of the WinSock API
#pragma comment(lib,"WSOCK32.LIB")
using namespace std;
void main()
{
WSADATA wsadata;
SOCKET sock;
int err,i,startport=1,endport=1024;
char ip[20];
struct sockaddr_in sock_addr;
FILE *j;//j is a pointer
cout<<"please enter ip"<<endl;
cin>>ip;
cout<<"please enter start port"<<endl;
cin>>startport;
cout<<"please enter end port"<<endl;
cin>>endport;
if((WSAStartup(MAKEWORD(2,2),&wsadata)!=0))
{
cout<<"WSAstartup error"<<endl;
}
else
{
for(i=startport;i<=endport;i++)
{
sock=socket(AF_INET,SOCK_STREAM,0);//create a stream TCP socket
sock_addr.sin_family=PF_INET;
sock_addr.sin_port=htons(i);//convert to network byte
sock_addr.sin_addr.s_addr=inet_addr(ip);
cout<<"scanning"<<endl;
err=connect(sock,(struct sockaddr*)&sock_addr,sizeof(struct sockaddr));
if(err==0)
{
cout<<"Port Open"<<endl;
j=fopen("ports.txt","a+");
cout<<j<<"Port is open"<<endl;
closesocket(sock);
fclose(j);
}
else
{
cout<<"Port Closed"<<endl;
}
}
WSACleanup();
system("ports.txt");
}
}
یه برنامه پورت اسکنر نوشتم که یک آی پی می گیره و برای یک رنج پورت اون رو بررسی می کنه که باز هست یا بسته ولی می خوام که یک رنج آی پی بگیره و بعد این بررسی رو انجام بده ....مثلا یه آی پی شروع و یه آی پی پایان بگیره و بعد شماره آی پی رو تو حلقه افزایش بده کسی میدونه باید چی کار کنم؟؟؟؟
در واقع برای گرفتن یک رنج آی پی چه پیشنهادی دارید؟
#include <iostream>
#include <winsock2.h>//definitions to be used with the WinSock 2 DLL and WinSock 2 applications This header file corresponds to version 2.2.x of the WinSock API
#pragma comment(lib,"WSOCK32.LIB")
using namespace std;
void main()
{
WSADATA wsadata;
SOCKET sock;
int err,i,startport=1,endport=1024;
char ip[20];
struct sockaddr_in sock_addr;
FILE *j;//j is a pointer
cout<<"please enter ip"<<endl;
cin>>ip;
cout<<"please enter start port"<<endl;
cin>>startport;
cout<<"please enter end port"<<endl;
cin>>endport;
if((WSAStartup(MAKEWORD(2,2),&wsadata)!=0))
{
cout<<"WSAstartup error"<<endl;
}
else
{
for(i=startport;i<=endport;i++)
{
sock=socket(AF_INET,SOCK_STREAM,0);//create a stream TCP socket
sock_addr.sin_family=PF_INET;
sock_addr.sin_port=htons(i);//convert to network byte
sock_addr.sin_addr.s_addr=inet_addr(ip);
cout<<"scanning"<<endl;
err=connect(sock,(struct sockaddr*)&sock_addr,sizeof(struct sockaddr));
if(err==0)
{
cout<<"Port Open"<<endl;
j=fopen("ports.txt","a+");
cout<<j<<"Port is open"<<endl;
closesocket(sock);
fclose(j);
}
else
{
cout<<"Port Closed"<<endl;
}
}
WSACleanup();
system("ports.txt");
}
}