IP Address Swapping

Environment: VC 6, NT4

This is an application used to swap the IP address. For connecting to a computer in different domain the user has to change the IP address through the Network properties, for this the user has to follow 3 to 4 steps.

In this application, the IP address of your computer will be displayed in the listbox,the user can double click it to set it as the current IP address.
  • This application can be used only in Windows NT 4.0
  • The user should have the administrator privilege

This is a trial version for swapping the IP address in your computer. Later version will be updated frequently

Warning:This application uses the registry for manipulating the IP address.

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// IPswapDlg.cpp : implementation file

#include "stdafx.h"
#include "IPswap.h"
#include "IPswapDlg.h"


BOOL CIPswapDlg::OnInitDialog()
{

  IPList=(CListBox*)GetDlgItem(IDC_IPADDLST);
  HKEY AppKey = NULL;
  LONG lRet1 = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
     "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Linkage",
     0,
     KEY_EXECUTE|KEY_READ|KEY_ALL_ACCESS,
     &AppKey);
  DWORD dwS=MAXPATH;
  unsigned char szPath[MAXPATH];
  if(RegQueryValueEx(AppKey,"Bind",NULL,NULL,szPath,&dwS))
  {
    AfxMessageBox("Error Accessing Registry");
  }
  NetAdapt=(CString)szPath;
  NetAdapt.MakeReverse();
  int slash=NetAdapt.Find("\\",0);
  NetAdapt=NetAdapt.Left(slash);
  NetAdapt.MakeReverse();
  IPList->ResetContent();
  HKEY AppPathKey = NULL;

  LONG lRet = RegOpenKeyEx(
     HKEY_LOCAL_MACHINE,
     "SYSTEM\\CurrentControlSet\\Services\\"+
            NetAdapt+"\\Parameters\\Tcpip",
     0,
     KEY_EXECUTE|KEY_READ|KEY_ALL_ACCESS,
     &AppPathKey);
  DWORD dwSize = MAXPATH;
  DWORD dwSize1 = MAXPATH;
  unsigned char szAppPath[MAXPATH];
  unsigned char szAppPath1[MAXPATH];
  CString FullIP,SubnetMask;
  if( RegQueryValueEx( AppPathKey,
                       "IpAddress",
                       NULL,
                       NULL,
                       szAppPath,
                       &dwSize)!= ERROR_SUCCESS )
  {
     AfxMessageBox("Error while Accessing registry");
     return 0;
  }
  else
  {
     for(int i=0;i<255;i++)
       if((CString)szAppPath[i]!="")
       FullIP=FullIP+(CString)szAppPath[i];
       else
       {
          if(FullIP.GetLength()>=8)
          {
            IPList->AddString(FullIP);
          }

          FullIP="";
       }

  }

  if(RegQueryValueEx( AppPathKey,
                      "SubnetMask",
                      NULL,
                      NULL,
                      szAppPath1,
                      &dwSize1)!= ERROR_SUCCESS )
  {
     AfxMessageBox("Error while Accessing registry");
     return 0;
  }
  else{

     for(int i=0;i<255;i++)
       if((CString)szAppPath1[i]!="")
       SubnetMask=SubnetMask+(CString)szAppPath1[i];
       else
       {
         if(SubnetMask.GetLength()>=8)
         {
         subnetarray.Add(SubnetMask); 
         }
        
         SubnetMask="";
       }
       
  }



  RegCloseKey(AppPathKey);

  return TRUE;  // return TRUE  unless you set 
                // the focus to a control
}


void CIPswapDlg::OnDblclkIpaddlst() 
{
  CString teststr,teststr1;
  CString iptobemoved=iparray.GetAt(0);
  CString subnettobemoved=subnetarray.GetAt(0);

  int curr=IPList->GetCurSel();
  if(curr==0) return;
  teststr=iparray.GetAt(curr);
  teststr1=subnetarray.GetAt(curr);

  iparray.SetAt(curr,iptobemoved);
  iparray.SetAt(0,teststr);
  subnetarray.SetAt(curr,subnettobemoved);
  subnetarray.SetAt(0,teststr1);

  IPList->ResetContent();

  HKEY AppPathKey = NULL;
  LONG lRet = RegOpenKeyEx(  HKEY_LOCAL_MACHINE,
                "SYSTEM\\CurrentControlSet\\Services\\"+
                NetAdapt+"\\Parameters\\Tcpip",
                0,
                KEY_EXECUTE|KEY_READ|KEY_ALL_ACCESS,
                &AppPathKey);

  DWORD dwSize = MAXPATH;
  unsigned char szAppPath[MAXPATH];
  CString FullIP;
  if(RegQueryValueEx( AppPathKey,
                      "IpAddress",
                      NULL,
                      NULL,
                      szAppPath,
                      &dwSize)!= ERROR_SUCCESS )
  {
     AfxMessageBox("Error while Accessing registry");
     return;
  }
  int z=0;
  unsigned char ii[100];
  unsigned char subne[100];
  CString ip,sn;

  for(int p=0;p<=iparray.GetSize()-1;p++)
  {
     ip=iparray.GetAt(p);
     for(int k=0;k<=ip.GetLength()-1;k++)
     {
       ii[z]=ip.GetAt(k);
       z=z+1;
     }
     ii[z]='\0';
     z++;
  }
  int x=0;
  for(int q=0;q<=subnetarray.GetSize()-1;q++)
  {
     sn=subnetarray.GetAt(q);
     for(int k=0;k<=sn.GetLength()-1;k++)
     {
       subne[x]=sn.GetAt(k);
       x=x+1;
     }
     subne[x]='\0';
     x++;
  }


  RegSetValueEx(AppPathKey,"IpAddress",0,REG_MULTI_SZ,ii,z);
  RegSetValueEx(AppPathKey,"SubnetMask",0,REG_MULTI_SZ,subne,x);
  RegCloseKey(AppPathKey);
  for(int j=0;j<=iparray.GetSize()-1;j++)
  {
     IPList->AddString(iparray.GetAt(j));
  }

     MessageBox("Successfully swaped");
}

Downloads

Download demo project - 9Kb
Download source - 22Kb


Comments

  • winsock programming

    Posted by Legacy on 03/02/2003 12:00am

    Originally posted by: reza

    Hello...
    I need to the winsock programming comments.
    by...

    Reply
  • How to get dynamic ip

    Posted by Legacy on 09/23/2002 12:00am

    Originally posted by: ramesh

    How to get dyanamic ip address when my computer(proxy client) is connected to internet

    • Help

      Posted by Mirtunjay on 02/26/2008 07:49am

      Hi i have same problem,so you will give me source code..if it is possible then mail me mirtunajy.prodata@gmail.com

      Reply
    • System network implementation does that by itself.

      Posted by turkinz on 12/22/2005 09:07pm

      Or, if you need to write your own API to get the IP form DHCP Server you need to see RFC's on DHCP and TCP/IP Specification and MSDN on TCP/IP programing. DHCP data are broadcast always to a fixed static IP address: 255.255.255.255

      Reply
    Reply
  • Can u help me to learn more about IP

    Posted by Legacy on 06/16/2002 12:00am

    Originally posted by: Ayyappan

    I want to learn more about VC++ and IP .Please help me 
    
    

    With solutions.

    Reply
  • I want to do IP-spoofing, can u help me?

    Posted by Legacy on 06/13/2002 12:00am

    Originally posted by: Pranav

    I want to do ip spoofing. i.e. i have two internet connections on my PC. I want to send mails from one connection with header information of other.

    Reply
  • IP Address Swapping

    Posted by Legacy on 04/04/2002 12:00am

    Originally posted by: Parag Deshpande

    Is it possible to swap the machine ip with Dial up ip
    i.e: machine IP: 192.168.1.15
    Dial up IP: 61.1.80.220
    after swapping
    Both IP's: 61.1.80.220

    Reply
  • Ip address swapping

    Posted by Legacy on 03/13/2002 12:00am

    Originally posted by: Kirthieswar

    Effective.Can be refined.

    Reply
  • Outstanding

    Posted by Legacy on 02/05/2002 12:00am

    Originally posted by: shreeja

    Sir,
    It is very useful for me because i use to change my ip address everytime while iam connecting to net

    thanks a lot

    i think u can do a lot with system propramming

    all the best

    Reply
  • Excellent

    Posted by Legacy on 01/31/2002 12:00am

    Originally posted by: Manoj

    It is working fine.It is very useful for Our concern.
    Thanks a lot...

    Reply
  • Modify in win2000

    Posted by Legacy on 01/16/2002 12:00am

    Originally posted by: Bill.Dai

    If the os is window 2000,should add the following after NetAdapt.MakeReverse() in BOOL CIPswapDlg::OnInitDialog function:
    NetAdapt.Delete(0,NetAdapt.Find('{'));

    Reply
  • Very unprofessional

    Posted by Legacy on 01/15/2002 12:00am

    Originally posted by: Andrey Koubychev

    I think you should use IP Helper API for changing IP address. However i have never meet any situation when it was needed to do automatically. Just assign few IPs to your adapter and bind from app to address you need to use.

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds