Resolve Decimal IP Addresses with this Simple C Program

Resolve Decimal IP Addresses with this Simple C Program

Post by Felix Tille » Fri, 12 Feb 1999 04:00:00



/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
/* Felix Tilley */

/* No Guarantees on how this will run on your computer. */
/* An unsigned long must be AT LEAST 32 bits for this to work */
/* An unsigned long must be AT LEAST 32 bits for this to work */
/* An unsigned long must be AT LEAST 32 bits for this to work */

/* NO JOKE */

#include <stdio.h>

main()
{
unsigned long webaddr, quad0, quad1, quad2, quad3, quotient, temp, remainder;

printf ("Enter web address as decimal:   ");

scanf ("%lu", &webaddr);
printf ("\nWEB ADDRESS:      %lu \n", webaddr);

quad0    = webaddr  % 256;
quotient = webaddr  / 256;

quad1    = quotient % 256;
quotient = quotient / 256;

quad2    = quotient % 256;
quotient = quotient / 256;

quad3 = quotient;

printf ("QUAD IP ADDRESS:  %lu\.%lu\.%lu\.%lu  \n", quad3,quad2,quad1,quad0);

printf ("\nHope this helps.\nFelix Tilley \n");

exit(0) ;

Quote:}

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by Bob Blayloc » Fri, 12 Feb 1999 04:00:00


#include <stdio.h>
#include <stdlib.h>

 #ifdef macintosh
   #if macintosh
    #define __CCMD__
   #endif
 #endif

  #ifdef __CCMD__
   #include <console.h>
  #endif

char *IPcvt(char s[])
{
 static char result[1024];
 unsigned long a,b,c,d,ip;
 register int ii;

 ii = sscanf(s,"%lu.%lu.%lu.%lu",&a,&b,&c,&d);
  switch(ii)
  {
   case 1:
    ip = a;
    a = (ip>>24) & 0xff;
    b = (ip>>16) & 0xff;
    c = (ip>>8) & 0xff;
    d = ip & 0xff;
    sprintf(result,"%s = %lu.%lu.%lu.%lu",s,a,b,c,d);
    break;
   case 4:
    ip = (a<<24) | (b<<16) | (c<<8) | d;
    sprintf(result,"%s = %lu",s,ip);
    break;
   default:
    sprintf(result,"Invalid input:  %s",s);
    break;
  }
 return(result);

Quote:}

main(int argc, char *argv[])
{
  #ifdef __CCMD__
   argc = ccommand(&argv);
  #endif

  if(argc > 1)
  {
   register int ii;

   for(ii=1;ii<argc;ii++)  puts(IPcvt(argv[ii]));
  }
  else
  {
   char line[1024];

   gets(line);
    while(!feof(stdin))
    {
     puts(IPcvt(line));
     gets(line);
    }
  }

Quote:}

--
I hunt down and kill spammers and similar net-vermin.  Do not send
any form of advertising, bulk email, chain letters, or similar
garbage to me, unless you wish to be my next prey.
Web Site:  http://www.impulse.net/~thebob

To email me, remove ".die.spammers.die" from the address.

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by Hello Kittyha » Sat, 13 Feb 1999 04:00:00




|
|/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
|/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
|/* Felix Tilley */

        ...or try the simple unix shell script below...

--
  ,u,    Bruce Becker           Toronto, Ontario        1 416 699 1868

 `/o/-e  +woodpecker +radio +USSR +power
 _\ >_                                       - D. M. Procida

 --------- 8< --------- 8< --------- 8< --------- 8< --------- 8< ---------

#!/bin/sh

echo "obase=256; $1" | bc | awk '
{
        for (i=1; i <= NF; i++) {
                s=$i
                if      (s ~ /^00/)
                        s=substr(s,3)
                else if (s ~ /^0/)
                        s=substr(s,2)
                if (i == 1)
                        S = s
                else
                        S = S "." s
        }
        print S

Quote:}' -

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by Bill Malo » Sat, 13 Feb 1999 04:00:00


[ snip Decimal -> dotted Quad conversion program, rev 0 ]

Here's an obfuscated (no Math) version:

/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
/* Felix Tilley */

/* No Guarantees on how this will run on your computer. */
/* An unsigned long must be AT LEAST 32 bits for this to work */
/* An unsigned long must be AT LEAST 32 bits for this to work */
/* An unsigned long must be AT LEAST 32 bits for this to work */

/* NO JOKE */
/* Rev 1 */

#include <stdio.h>

main() {
char dot = '.';
union {
        unsigned char quad[4];
        unsigned long decimal;

Quote:} webaddr;

printf ("Enter web address as decimal:   ");

scanf ("%lu", &webaddr.decimal);
printf ("\nWEB ADDRESS:      %lu \n", webaddr.decimal);

printf ("QUAD IP ADDRESS:  %lu%c%lu%c%lu%c%lu  \n",
  webaddr.quad[3],dot,
  webaddr.quad[2],dot,
  webaddr.quad[1],dot,
  webaddr.quad[0]);

/* You may need to reverse the order on the subscripts, above */

printf ("\nHope this helps.\nFelix Tilley\n");
exit(0) ;

Quote:}

Check:
$ ./tilley
Enter web address as decimal:   123456789

WEB ADDRESS:      123456789
QUAD IP ADDRESS:  7.91.205.21

Hope this helps.
Felix Tilley
$ ping 123456789
PING 123456789 (7.91.205.21): 56 data bytes

--
Bill Maloy (brm4)              |  Here's where my .sig references
"Death before mungement"       |  "the understated politeness of
A.S. Cadre #47                 |   Ron Schwarz" for no apparent reason.

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by John Oliv » Tue, 16 Feb 1999 04:00:00





>|
>|/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
>|/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
>|/* Felix Tilley */

>    ...or try the simple unix shell script below...

...or 'ping xxxxxxxxxx'... :-)

--
If you want to reply to me, do it in the newsgroup... It's
been too long since I've received anything other than spam
in my mailbox from posting my address in the newsgroups.

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by Jerry Bookt » Wed, 17 Feb 1999 04:00:00



Quote:(John Oliver) writes:

:>

:>


:>>|
:>>|/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
:>>|/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
:>>|/* Felix Tilley */
:>>
:>>
:>>       ...or try the simple unix shell script below...
:>

Or ping, or traceroute.....

--Jerry in Columbia
WARP'der'n hell down South with OS/2
*Visit Big Boy and Sweetheart's (tm)Parrot-Approved Web Site at*
http://www.conterra.com/bookter/bigboy.htm

 
 
 

Resolve Decimal IP Addresses with this Simple C Program

Post by Norman L. DeFores » Sun, 21 Feb 1999 04:00:00




: |/* TURN A 32 BIT DECIMAL IP ADDRESS INTO 4 QUADS */
: |/* SPAMMERS CAN RUN, BUT THEY CAN'T HIDE */
: |/* Felix Tilley */

On Fri, 12 Feb 1999, Hello Kittyhawk followed with:

Quote:>    ...or try the simple unix shell script below...

Or 4DOS users (NOT DOS 4 users) can use the alias (entered as ONE line
although broken up here at spaces for legibility):



]^echo.`

Usage:

C:\>dot 3226165073

 3226165073  =  192.75.95.81

C:\>( dot 3226165073 ) >convertd.txt

4DOS command-grouping needed because of the multiple echo statements.
If you don't mind things being crowded on the screen, you can shorten the
alias to:



and command-grouping wouldn't be needed:

Usage:

C:\>dot 3226165073
 3226165073  =  192.75.95.81

C:\>dot 3226165073  >convertd.txt

Norman De Forest            http://www.chebucto.ns.ca/~af380/Profile.html

My response to a Net Kook:   http://www.chebucto.ns.ca/~af380/Carmlo.html
Spammers, see:      http://www.chebucto.ns.ca/~af380/Profile.html#Contact

 
 
 

1. How to configure sendmail when addressing by IP addresses (user@[ip-address-of-sendmail-host])?

Hello,

Been searching through google for help but couldn't find what I need.  I'm
try to send mail to my server using it's IP address.  I'm fine sending mail


fails giving me a nice message in the maillog:

config error: mail loops back to me

I do the same, but this time, I write the email from another machine to


relay=blah.c003.blah.blah.net [119.228.222.229], reject=550 5.7.1

Any clues?  I already modified /etc/mail/access and added the sendmail
host's IP address there.

Thanks

2. Looking for letterhead fonts for law office

3. webaddr.c: Convert spammer decimal IP's to 4 quads

4. MegaMac

5. Cannot resolve IP addresses with named daemon running.

6. RAS in .net

7. Resolving an IP Address.

8. pgp and pine

9. Blocking relay IP addresses that don't resolve?

10. Resolving raw IP addresses

11. Any statistic program which can gernerate the mail traffic from the IP address

12. Virtual hosts - IP based using own IP address

13. Sharing desktops: both clients on private IP LANs connected by routers with 1 IP static address