C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,495 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,850 people online right now. Registration is fast and FREE... Join Now!




Resolving the currently connected ISP

 

Resolving the currently connected ISP

RobG

2 Jul, 2009 - 02:22 PM
Post #1

New D.I.C Head
*

Joined: 26 May, 2007
Posts: 11


My Contributions
Has anyone any ideas on resolving the currently connected ISP.
I don't really want to resort to system 'trace' call and I cant find
any mechanism in winsock.

Any help would be much appreciated.




User is offlineProfile CardPM
+Quote Post


mischief6

RE: Resolving The Currently Connected ISP

2 Jul, 2009 - 08:35 PM
Post #2

New D.I.C Head
*

Joined: 9 Jan, 2009
Posts: 21



Thanked: 1 times
My Contributions
an easy way to do this is to connect to a site or protocol which reports your external IP. from there you can attempt to resolve it through reverse DNS and use the ISP-assigned hostname to figure out the ISP, or use a lookup table of mapped IP ranged to ISPs.
User is offlineProfile CardPM
+Quote Post

RobG

RE: Resolving The Currently Connected ISP

3 Jul, 2009 - 02:09 AM
Post #3

New D.I.C Head
*

Joined: 26 May, 2007
Posts: 11


My Contributions
QUOTE(mischief6 @ 2 Jul, 2009 - 08:35 PM) *

an easy way to do this is to connect to a site or protocol which reports your external IP. from there you can attempt to resolve it through reverse DNS and use the ISP-assigned hostname to figure out the ISP, or use a lookup table of mapped IP ranged to ISPs.

Thanx Mischief, but I cant find any c\c++ code for reverse DNS lookup out there.
A few dll's but nothing that I would want to trust and all as far as I can see all require
user input and I want full automation.

I'll tell you what my problem is... I'm working on a small project to send email when
Im out on the road or visiting any friendly LAN. Assuming that there is full permission
or its a free WiFi link.

On the road and waiting for the first WiFi link to pass my waiting mail through,
trouble is that most WLANs don't allow you to send smtp through the link unless their
ISP happens to coincide with your own nominated ISP. So if you have your code set
as gethostbyname("smtp.whatever.com") and the LAN doesn't happen to be "whatever.com"
you'll go nowhere in a hurry. No, in this case the hostent structure for gethostbyname can
only be created dynamically.

Ive only just moved into ftp and email and Im really struggling on this on.







User is offlineProfile CardPM
+Quote Post

perfectly.insane

RE: Resolving The Currently Connected ISP

5 Jul, 2009 - 02:25 PM
Post #4

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 635



Thanked: 62 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
QUOTE(RobG @ 3 Jul, 2009 - 05:09 AM) *

Thanx Mischief, but I cant find any c\c++ code for reverse DNS lookup out there.
A few dll's but nothing that I would want to trust and all as far as I can see all require
user input and I want full automation.


Doing that component in C++ isn't strictly necessary. The only part that is necessary is connecting to the web service. The web service can do the reverse lookup for you.

Example (perl CGI):

CODE

#!/usr/bin/perl

use Net::IP;
use Net::DNS;
use CGI;
use strict;
use warnings;

my $cgi = new CGI;
my $ip = new Net::IP($cgi->remote_addr());
my $res = new Net::DNS::Resolver();
my $answer = $res->query($ip->reverse_ip(), 'PTR');
my $name = ($answer->answer())[0];

print "Content-type: text/plain\n\n" . $name->{ptrdname} . "\n";


Requesting this information requires doing a HTTP GET request from C++, which is not extremely difficult to do, even when implementing it on top of a BSD-compatible sockets API.
User is offlineProfile CardPM
+Quote Post

RobG

RE: Resolving The Currently Connected ISP

7 Jul, 2009 - 07:11 AM
Post #5

New D.I.C Head
*

Joined: 26 May, 2007
Posts: 11


My Contributions
Many thanx Perfectly.Insain, this may be a watershed for me, not quite sure yet.
HTTP no probs. Perl on the other hand, Ive always stood well back from, apart from
my occasional trips into Symbian Ive never really needed it. But I suppose if that's
what it takes to join the ranks of Network Coders then so be it. That said, can't
get it to work at the moment. Ive tried Dev, Code:Blocks and Borland, none will wear
it. A couple of hours on the web and the best I can find are one or two commercial enterprises
offering purpose designed libraries allowing Perl to be inserted into c++.
I've got the obvious includes in place ...
#include "c:\Perl\lib\core\EXTERN.h"
#include "c:\Perl\perl.h"
Maybe I've missed something or could be that I'm just plain thick. Please tell, how's it done?


User is offlineProfile CardPM
+Quote Post

perfectly.insane

RE: Resolving The Currently Connected ISP

7 Jul, 2009 - 08:52 AM
Post #6

D.I.C Addict
Group Icon

Joined: 22 Mar, 2008
Posts: 635



Thanked: 62 times
Dream Kudos: 25
Expert In: C/C++

My Contributions
QUOTE(RobG @ 7 Jul, 2009 - 10:11 AM) *

Many thanx Perfectly.Insain, this may be a watershed for me, not quite sure yet.
HTTP no probs. Perl on the other hand, Ive always stood well back from, apart from
my occasional trips into Symbian Ive never really needed it. But I suppose if that's
what it takes to join the ranks of Network Coders then so be it. That said, can't
get it to work at the moment. Ive tried Dev, Code:Blocks and Borland, none will wear
it. A couple of hours on the web and the best I can find are one or two commercial enterprises
offering purpose designed libraries allowing Perl to be inserted into c++.
I've got the obvious includes in place ...
#include "c:\Perl\lib\core\EXTERN.h"
#include "c:\Perl\perl.h"
Maybe I've missed something or could be that I'm just plain thick. Please tell, how's it done?


Actually, the idea is to set up a web service that is separate from your client program. The example I provided can be used with an Apache HTTP server as a CGI script. This web server should be accessible on the Internet by the client system (where your C++ program is running).

Let's say that the computer running the HTTP server has a domain name of hostnamereporter.net pointing to it, and the script name is hostname.pl, residing in the cgi-bin directory. If I point a web browser to http://hostnamereporter.net/cgi-bin/hostname.pl, if the server is set up correctly, it should report my host name (as resolved by reverse lookup). I can write a C++ program that does the same thing (connects to hostnamereporter.net on port 80, sends a GET /cgi-bin/hostname.pl HTTP/1.0, and reads the result).

There are other ways of implementing the service, such as using server-side preprocessing (PHP, ASP), SOAP, XML-RPC, or even a custom protocol, but I'm using CGI as an example because it's simple and there is quite a bit of existing information about it.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/8/09 04:51AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month