|
|
Hello
I have written a client-server program using VC++ 2012 console application, which works on local network properly. But I want to connect to the server program on the internet using client program. I have the computer IP that server program is run on. How can I connect to server program by client?
(regards)
|
|
|
|
|
Exactly the same way you connect to it on the lan: by IP address.
|
|
|
|
|
Thank you for your advice, But it didn’t work. I decided to run server program on one of computers in my office. For this purpose I got that computer’s IP address from http://myip.dnsomatic.com and used it in server program. But error code 10049 was returned. (Cannot assign requested address) :
WSAData ws;
struct sockaddr_in sock;
int resSock, cl,bnd;
WSAStartup(MAKEWORD(2, 2), &ws);
resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (resSock != INVALID_SOCKET){
sock.sin_family = AF_INET;
sock.sin_port = htons(3377);
sock.sin_addr.S_un.S_addr = inet_addr("86.57.x.y");
}
bnd = bind(resSock, (struct sockaddr *)&sock, sizeof(sock));
if (bnd != SOCKET_ERROR)
cout << "Successfull..." << endl;
else
cout << GetLastError() << endl;
|
|
|
|
|
zartosht_ppp wrote: I got that computer’s IP address from http://myip.dnsomatic.com and used it in server program. You should be using the address from the client to reach the server. And you cannot use the address "86.57.x.y", it does not mean anything.
|
|
|
|
|
That was just an example. I know it doesn't mean anything. anyway thank you for your guide.
|
|
|
|
|
zartosht_ppp wrote: I decided to run server program on one of computers in my office. For this purpose I got that computer’s IP address from http://myip.dnsomatic.com and... But is that computer visible to the outside world? In most offices, it would not be.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
In my office, it's possible. I just want a solution. Let me know if you have one.
|
|
|
|
|
There are a lot of things that could be in the way... can you ping between the two machines? Just having internet access isn't really enough, a lot of times certain ports are blocked off to prevent external intrusions. There could be firewalls blocking access both within the machine and externally as part of the network.
|
|
|
|
|
Look, my problem is that server program doesn’t bind to the valid IP such as 86.57.91.230. But it binds to the invalid IP such as 192.168.0.1.
|
|
|
|
|
You should let the system choose which address to bind to, rather than trying to force it. The chances are that the address you have is not the address of a network adapter on that system.
|
|
|
|
|
Is that IP address 86.57.... the IP address on your router that the outside world sees?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
|
Have you set your router up to port forward requests from the outside world to your machine? Have you open up that port on your firewall? You need to bind to your local IP address (192.168....) and have the router forward those external requests to your machine.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
Thank you so much, it worked.
Now I want to develop the program and write a program such as NETCAT. I want the victim stays at listening state after running the program.
The question is how the victim get its public IP to stays at listening state with that IP?
|
|
|
|
|
Not sure what you mean by victim, nor am I familiar with netcat. Try clarifying your question and perhaps create a new thread on this forum.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
ok. Here is about NETCAT (http://en.wikipedia.org/wiki/Netcat)
I have written a program in two client and server versions. The server program must be run on the victim computer. I’m controlling the whole of the victim computer by client program. I’ve written this program for LAN. Now I want this program works on the internet while controlling that victim computer with the server program on. The victim computer is connected to the internet by and ADSL broadband. My problem is when the server program is being run on the victim computer, how it can get the Public IP and then stays at listening state on that IP address?
|
|
|
|
|
Sounds difficult, as the ADSL router probably doesn't have a static IP address, but if it did, the server software would listen to the local machines' (private) IP address (this probably isn't static either), and the ADSL router would need to have port forwarding setup to send your server machine incoming packets. Lots of this (I'm guessing) is not done programatically. here[^] is an example of the type of setup needed.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
Dear friend, It’s not important if that public IP (ADSL IP) be static or dynamic. The code below gets public IP of that computer and it must be able bind that IP to the created socket and then stays at the listening state:
...
HINTERNET hI, hF;
DWORD piSize;
char public_ip[15];
hI= InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
hF = InternetOpenUrlA(hI, "http://myip.dnsomatic.com", NULL, 0, INTERNET_FLAG_RELOAD, 0);
InternetReadFile(hF, &public_ip, sizeof(public_ip), &piSize);
public_ip[piSize] = '\0';
InternetCloseHandle(hF);
InternetCloseHandle(hI);
cout << public_ip;
...
The main problem is that my server program can’t bind to received public IP.
|
|
|
|
|
You want to bind to an IP address associated with a NIC on a seperate device (ADSL router)? If so, I don't think you can, and you don't need to (think port forwarding). If not, I'm still not sure what your question is.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
It's confusing!
Let’s imagine my public IP address is 86.57.91.237.
Now I want to use that IP in the code below:
...
WSAData ws;
struct sockaddr_in sock;
int resSock, bnd;
WSAStartup(MAKEWORD(2, 2), &ws);
resSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (resSock != INVALID_SOCKET){
sock.sin_family = AF_INET;
sock.sin_port = htons(3377);
sock.sin_addr.S_un.S_addr = inet_addr("86.57.91.237");
}
bnd=bind(resSock, (struct sockaddr *)&sock, sizeof(sock));
if (bnd != SOCKET_ERROR)
cout << "Bind Successful" << endl;
else
cout << GetLastError() << endl;
...
why does this program show error code 10049? Error code 10049 means:
“The requested address is not valid in its context. This normally results from an attempt to bind to an address that is not valid for the local computer”.
I want to see “Bind Successful” message.
|
|
|
|
|
Run "ipconfig /all" at the command prompt. Look at the results, there should be data given about each NIC card on YOUR machine. Look at the line that says "IP Address.......xxx.xxx.xxx.xxx" (there may be several). Make a list of these IP addresses. If "86.57.91.237" is not in that list, then you can not bind to it. Meaning it is not an IP address associated with a NIC on your computer.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
|
|
|
|
|
Here is my Program
In the line int GCD(num1,num2) I get the warning
" warning: parameter names (without types) in function declaration [enabled by default]| "
But if I use int GCD(int a,int b) the warning is not there.
NOTE - In both cases the program runs perfectly.
I am a newbie, so I would appreciate if someone helps me regarding this....
/* I am using mingw with code blocks */
#include<math.h>
#include<stdio.h>
#include<conio.h>
int GCD(num1,num2);
main()
{
int num1,num2;
printf("\n\tEnter the two numbers whose GCD is to be found : ");
scanf("%d %d",&num1,&num2);
printf("\n\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
getch();
}
int GCD(int a ,int b)
{
if (b>a)
return GCD(b,a);
if(b==0)
return a;
else
return GCD(b,a%b);
}
#include<math.h>
#include<stdio.h>
#include<conio.h>
int GCD(num1,num2);
main()
{
int num1,num2;
printf("\n\tEnter the two numbers whose GCD is to be found : ");
scanf("%d %d",&num1,&num2);
printf("\n\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
getch();
}
int GCD(int a ,int b)
{
if (b>a)
return GCD(b,a);
if(b==0)
return a;
else
return GCD(b,a%b);
}
#include<math.h>
#include<stdio.h>
#include<conio.h>
int GCD(num1,num2);
main()
{
int num1,num2;
printf("\n\tEnter the two numbers whose GCD is to be found : ");
scanf("%d %d",&num1,&num2);
printf("\n\tGCD of %d & %d is %d",num1,num2,GCD(num1,num2));
getch();
}
int GCD(int a ,int b)
{
if (b>a)
return GCD(b,a);
if(b==0)
return a;
else
return GCD(b,a%b);
}
|
|
|
|
|
You should always declare the parameter types to avoid confusion.
|
|
|
|
|
So i need to specify that they are integers, right ? 
|
|
|
|