Thread: Lets Start A New Standard Service!

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    265

    Lightbulb Lets Start A New Standard Service!

    Okeydokey, Lots of people have problems translating IPs since NAT came into existance. Internal network IPs, External Network IPs, IPs used over some WAN interface. Its just a pain in the ass. There have been ALOT of questions between several threads here and threads on other forums for even other languages looking for a simple way to obtain your EXTERNAL IP address. (The One That The Internet Sees!)

    What I Propose: We should enact a new standard service that runs on an arbitrarily assigned unused port, (Im thinking port 412 just for $$$$s and giggles.) That accepts a connection from a host, simply prints the IP of the connecting host, and closes the connection. Boom. Simple, fast, effective. Then it will be a simple matter to run on multiple network servers, and possibly a few large central static points on the internet, such as a root nameserver, or one of the official NTP servers to determine how a given remote host will view your connection. This shouldnt take alot of work, involves no obvious security flaws, eats few if any system resources and bandwidth, and serves as an important network status and troubleshooting tool! Anybody interested in helping? Im thinking a simple "EchoIPd" IP Daemon writen in C (30 lines of code) and possibly a nice message to a few internet standards orginizations and we could have our own little chunk of immortality! What do you guys think?
    Last edited by Geolingo; 09-17-2003 at 07:20 PM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Sure, but we should probably use a port > 1024, just for safety.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Whats the use of it though? Why connect to an outside host to check your own IP address? Apart from it showing you what external address you use to access the server, I don't see much point in is

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    Yes, i know about the WhatIsMyIp.Com and other 200 sites out there that do this. However those are HTML and require your software to have added functionality of understanding HTTP, and being able to chop up HTML to get the IP out of it, and if those sites were to go down, or change format your entire section of code dealing with IP retrieval would need to be rewriten. Those sites are also not a portable service. Running several instances across wide area network connections to other campuses would require a webserver running to display your ip. 30 Lines of my daemon, or 30,000 of a webserver that uses 30 of php, perl or whatever server side scripted language you chose to use. Clearly mine is lower impact and alot easier to impliment. Did you know your IP changes at least 2 times and probablly more from when it leaves your computer to when it gets to the server your requesting a website from? Alot of it is transparent but problems do arise from this. Improperly configured NAT due to network administrator incompitence is a VERY common thing. Especially in cable networks such as roadrunner. The people that build the networks are generally alot smarter than the morons that run it from day to day. As your ip leaves your happy computer on your lan, it goes across your linksys router, and changes from 192.whatever your lan is using, to whatever your ISP is using. Some ISPs dont $$$$$ your IP out, however roadrunner does, like most cable networks. They run ALOT of traffic on the 10. subnet for internal traffic in their network. Your IP has changed twice now and its not even out on the internet. After it finally gets out there who knows how many other networks it passes through and concieveably changes in. Eventually it gets to the network the server your communicating is on, and guess what, it changes again from external ip, to internal ip, and who knows what that server is seeing you as. If they are implimenting load balancing you might be seen as the IP of the router that forwarded your packet, or one of a hundred other problems might occour. Collisions, signal loss, some router encrypting it and forgetting to decrypt it when it leaves their network (AOL is fameous for doing this over ATDN) and all sorts of other goodies. While this small small tool isnt useful for many home users, neither is ping or tracert provided on most home PCs. Its just another small tool to help make the lifes of the people that build the world, coders and network engineers, a little easier. And if it saves one sysadmin one headache because they simply telnet to port 4124 or whatever is chosen, then it was worth it.

  6. #6
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    ipconfig

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    IPconfig only returns the IP associated with the network interfaces on the local computer. We want to know how others view its IP. Not how it view its own IP.

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    DeepBlackMagic, I understand what you mean. List of things that DON'T work to get my proper IP address :

    -ipconfig
    -winipcfg
    -GetHostName()/GetHostByName()
    -connect()/GetSockName()
    -Some function that gives you a HOSTENT and makes you sort through 999 different IP addresses and arbitrarily pick one (maybe the GetHostName())
    -Also experimented with using the HTML servers, failed horribly...

    One thing, even when I go to those websites that tell you your IP, I can often get 2-3 different IP's returned, and I'm not sure they all work

    If you can get this pulled off... Wow, I'm going to fly over there and kiss you!
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    265

    Post Submitted For Your Approval

    Submitted for your approval, Code for the EchoIPDaemon:

    Code:
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <stdlib.h>
    #include <signal.h>
    #include <errno.h>
    #include <stdio.h>
    
    
    int terminate=0;
    
    void signalhd(int senal){
            if (senal==SIGINT){
                    printf("...Interrupt...\n");
                    terminate=1;
            }
    }
    
    void sigchld_handler(int s)
    {
    	while(wait(NULL) > 0);
    }
    
    
    int main()
    {
    
            struct sigaction sa;
    
    	struct sockaddr_in sin, fsin;
    	int s, ssock, alen;
    	char *ipaddress;
    
    
            sa.sa_handler = sigchld_handler;
            sigemptyset(&sa.sa_mask);
            sa.sa_flags = SA_RESTART;
            if (sigaction(SIGCHLD, &sa, NULL) == -1) {
                perror("sigaction");
                exit(1);
            }
    
    
    
    	sin.sin_family = AF_INET;
    	sin.sin_addr.s_addr = htonl(INADDR_ANY);
    	sin.sin_port = htons(6666);
    
    	if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0)
    	{
    		perror("Cant create socket");
    		exit(1);
    	}
    
    	if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0)
    	{
    		perror("Cant assign addres");
    		exit(2);
    	}
    
    	if (listen(s, 5) < 0)
    	{
    		perror("Cant turn to listening mode");
    		exit(3);
    	}
    
    	signal (SIGINT,signalhd);
    
    	while (1)
    	{
    		if (terminate==1)
    		{
    			close(s);
    			exit(0);
    		}
    		alen = sizeof(fsin);
    		if ((ssock=accept(s, (struct sockaddr *)&fsin, &alen)) < 0)
    		{
    			if (errno == EINTR) continue;
    			perror("Accept failed");
    			exit(4);
    		}
    
    		switch (fork()) {
    			case -1:{
    				perror ("Forking error");
    				exit (5);
    			}
    			case 0: {
    				close(s);
    				exit(0);
    			}
    			default: {
    				ipaddress=(char *)inet_ntoa(fsin.sin_addr);
    				write(ssock, ipaddress, strlen(ipaddress));
    				close(ssock);
    				break;
    			}
    		}
    	}
    	return 0;
    }
    Its short, sweet, and to the point. I ran it and stress tested it on an extremely low end box and it can do about 70 per second. Im looking for suggestions on how to speed it up or improve it. Im thinking about implimenting it on a university server with a static IP and trying to get somebody with power to recognise it. Using it would be a simple matter of telling your program to connect and take all recieved information and just convert it to an ip address or display it as a string or whatever.

  10. #10
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96
    You can try this:

    Co to Command Prompt.

    Type:

    Code:
    ping www.yourname.com
    Replace "www.yourname.com with any web site you wish to ping. That gives you the IP address.
    View in Braille.
    http://www.future-gpnet.com/braille.jpg

    Like a bolt out of the BLUE,
    Fate steps up and sees you THROUGH,
    When you wish upon a STAR
    YOUR DREAMS COME TRUE.

  11. #11
    Registered User
    Join Date
    Feb 2003
    Posts
    265
    i think your missing the point, Ping does print the ip of the remote server, as it does resolve the domain. However the object of this service isnt to identify the IP of the server its running on. It is for remote use to identify what YOUR seen as by that server.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Standard efficiency
    By Jorl17 in forum C Programming
    Replies: 3
    Last Post: 06-18-2009, 11:48 AM
  2. running my program as service
    By daher in forum Windows Programming
    Replies: 5
    Last Post: 09-05-2008, 12:30 PM
  3. IndiFTPD service
    By Tuborgrules in forum Windows Programming
    Replies: 3
    Last Post: 11-09-2005, 06:21 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. NT Service - researching...
    By schu777 in forum Windows Programming
    Replies: 3
    Last Post: 03-25-2002, 02:58 PM