Dynamic IP Hack

I have an RH7 Linux box into a large WinNT LAN.
All that WinNT servers gives me is a dynamic IP
address.
Before you can do anything else please save your
original /etc/hosts file.
  This is how you can hack that IP and put it in your
/etc/hosts file.
The testip.c program read the IP address from ifconfig
command and write it
into the /etc/hosts-up file.
I am newbie to Linuc c programming so don't laugh on
me for this C source file.

Compile: gcc setdynip.c -o setdynip

/* setdynip.c */
/* Written by Bubulac Angela Tatiana
([EMAIL PROTECTED],
[EMAIL PROTECTED] Copyright 20001, author
releases this source freely, allowing copying and
modification, so long as the original copyright notice
is maintained*/

#include <stdio.h>

int main(void)
{
FILE *fin,
     *popen();
char line[80],
     ipaddr[16],
     host_domain[]="deltacom.romtelecom.ro  
deltacom";
          
if ((fin = popen("ifconfig", "r")) != NULL)
   while (fgets(line,80,fin) != NULL)
      if (sscanf(line, "eth0 %s", ipaddr))
         {
          fgets(line,80,fin);
          sscanf(line, "               inet addr:
%15s", ipaddr);
         }
fclose(fin);
if ((fin = fopen("/etc/hosts-up", "w")) == NULL)      
   
   {
    fprintf(stderr, "Error in opening output file.
\n");
    exit(1);
   }
 
   fprintf(fin, "%s\n", "127.0.0.1     localhost"); 
 
   fprintf(fin, "%s   %s\n", ipaddr, host_domain);
   
fclose(fin);
return(0);
}

The resulting hosts-up file is:
127.0.0.1     localhost
172.20.64.102   deltacom.romtelecom.ro  deltacom


hosts-down file
127.0.0.1       deltacom.romtelecom.ro  localhost     
 deltacom

Put testip and hosts-up file in /sbin/ifup script
ifup script
......
      echo -n "Determining IP information for
${DEVICE}..."
    if /sbin/pump ${PUMPARGS} -i ${DEVICE} -h deltacom
; then
        echo " done. "
        echo "/sbin/pump -i ${DEVICE} --status"
    elif /sbin/dhcpcd ${DHCPCDARGS} ${DEVICE} ; then
        echo " done."
    else
        echo " failed."
        exit 1
    fi

echo "Testing IP ....."
if [ ! -f /usr/sbin/setdynip ]; then
    echo " testip file doesn't exist!"
    exit 0
fi
setdynip
cp /etc/hosts-up /etc/hosts

else
.........

Put hosts-down file to /sbin/ifdown script.
ifdown script
At the end of this script put
cp /etc/hosts-down /etc/hosts

Then type /etc/init.d/.network restart or reboot the
computer.
This work for me.



=====
Eng. Bubulac Angela Tatiana
IT Department, Romtelecom 
Phone: 4002804

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to