I'm trying to make my own ping program that can scan mutiple IP address on a local network. So the first part of the IP would be 192.168.1.xxx right? I'm trying to make it so that xxx goes up consecutively by 1. I'm a newbie at C but I think I should try to manipulate a string and then plug it into the system() function.
Here's what I have so far:
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int num_select(int x);
int num=0;
int input=0;
int main(void)
{
for(;;)
{
num_select(num);
system();
printf("\n%d", num);
}
}
int num_select(int x)
{
num++;
if(num%26gt;150) //I don't want it to scan over 192.168.1.150.
exit(0);
else
return num;
}
Making my own ping program in C?
Looks like you are scanning your router's DHCP range.
If you must do it your way, then your system will need input.
You don't need a num_select function since it's so small and you didn't static your num variable..it will get reset...Here's a quick rewrite.
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
int main(void)
{
int i;
char cmd[256];
for(i=1;i%26lt;=150;i++) {
sprintf(cmd,"ping -n 1 192.168.1.%d\n",i);
system(cmd);
}
}
Reply:the connection will be done through sockets. Just google C socket tutorial and you'll find something. Congratulations on learning C, great start. here's a website that is a great C tutorial:
brenda song
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment