IP Address Swapping
Posted
by C. SampathKumar
on January 14th, 2002
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 - 9KbDownload source - 22Kb

Comments
winsock programming
Posted by Legacy on 03/02/2003 12:00amOriginally posted by: reza
Hello...
ReplyI need to the winsock programming comments.
by...
How to get dynamic ip
Posted by Legacy on 09/23/2002 12:00amOriginally posted by: ramesh
How to get dyanamic ip address when my computer(proxy client) is connected to internet
-
-
ReplyHelp
Posted by Mirtunjay on 02/26/2008 07:49amHi i have same problem,so you will give me source code..if it is possible then mail me mirtunajy.prodata@gmail.com
ReplySystem network implementation does that by itself.
Posted by turkinz on 12/22/2005 09:07pmOr, 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
ReplyCan u help me to learn more about IP
Posted by Legacy on 06/16/2002 12:00amOriginally posted by: Ayyappan
ReplyI want to do IP-spoofing, can u help me?
Posted by Legacy on 06/13/2002 12:00amOriginally 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.
ReplyIP Address Swapping
Posted by Legacy on 04/04/2002 12:00amOriginally 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
ReplyIp address swapping
Posted by Legacy on 03/13/2002 12:00amOriginally posted by: Kirthieswar
Effective.Can be refined.
ReplyOutstanding
Posted by Legacy on 02/05/2002 12:00amOriginally 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
ReplyExcellent
Posted by Legacy on 01/31/2002 12:00amOriginally posted by: Manoj
It is working fine.It is very useful for Our concern.
ReplyThanks a lot...
Modify in win2000
Posted by Legacy on 01/16/2002 12:00amOriginally 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:00amOriginally 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.
ReplyLoading, Please Wait ...