| Cyberwarfare (112) | |
|
Hi, I am an learner in C++ Network programming anyway i want to find my IPv4 address but not 127.0.0.1. Please help. | |
|
|
|
| andywestken (1950) | |
|
Are you wanting your address on the private network your computer is connected to? That is, are you talking about a home or work/university/school network? (I'm assuming you're connected to a router of somekind.) Or your public address, as seen be someone across the Internet? Andy | |
|
Last edited on
|
|
| Cyberwarfare (112) | |
|
thanks for asking andy. I want to know my public Ipv4 address | |
|
|
|
| andywestken (1950) | ||
|
Well, it you haven't acquired a fixed IP address, it's not so easy. See this thread How to retrieve the IP Address Assigned to the machine by ISP http://serverfault.com/questions/18967/how-to-retrieve-the-ip-address-assigned-to-the-machine-by-isp According to this thread, the simplest solution is
Otherwise you'll need to talk to your router and ask it! (The information is not going to be on your local machine. It just need to know how to send stuff to your router) Andy Edit: Just checked my facts: my router know's its external address, and that of the host it's connected to. But the SNMP service is disabled, as I guess it would be for most domestic routers (by default) | ||
|
Last edited on
|
||
| Cyberwarfare (112) | |
| Yes . Thanks but the problem is that Once it finds you're IP it compare againt an other IP then if the IP is same then it Shows a message or something so you see the problem . | |
|
|
|
| andywestken (1950) | |
| Sorry, I don't follow you. | |
|
|
|
| Cyberwarfare (112) | |
| Sorry about that now i understand what you mean thanks sorry for the bothering and also sorry i just did not read ur post properly | |
|
|
|
| SamuelAdams (192) | |||
| |||
|
Last edited on
|
|||
| andywestken (1950) | |
|
@SamuelAdams The code you suggest is inappropriate as the OP does not want his local address (which is given by ipconfig). but his public IP address (as seen by people elsewhere in the Internet) And even if you do want the local address, there's no need to use the evil system, etc. You just call the function getaddrinfo() -- part of the socket API -- directly (rather than getting ipconfig to make the same call for you!) Andy PS If you search cplusplus.com for getaddrinfo you will find assorted examples of its use (and abuse). | |
|
Last edited on
|
|
| SamuelAdams (192) | |
|
Sorry I thought he wanted his local IPv4 Address. yea I know it's a hack If you have a working example of getaddrinfo(), would love to see it, can't seem to find anything online that works. | |
|
Last edited on
|
|
| modoran (1101) | |||
The example can be found in MSDN:
| |||
|
|
|||
| andywestken (1950) | ||
Well, I think you need to practice your goggling! It's a vital skill for all programmers, along with the use of other online resource like MSDN, The Linux Foundation, Apple Developer Connection, ... and cplusplus.com (as a searchable resource) When I google for "getaddrinfo example", the first five hits I get are (all with example code) Getaddrinfo http://en.wikipedia.org/wiki/Getaddrinfo creating sockaddr using getaddrinfo http://www.geekpage.jp/en/programming/winsock/getaddrinfo-1.php getaddrinfo.c http://www.logix.cz/michal/devel/various/getaddrinfo.c.xp getaddrinfo function (Windows) http://msdn.microsoft.com/en-gb/library/windows/desktop/ms738520%28v=vs.85%29.aspx GETADDRINFO(3) http://www.kernel.org/doc/man-pages/online/pages/man3/getaddrinfo.3.html Andy | ||
|
Last edited on
|
||