Results 1 to 4 of 4

Thread: Changing Ip adress, gateway & subnet mask of a connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    1

    Changing Ip adress, gateway & subnet mask of a connection



    Hi i'm trying to make a tool that can change a connections Ip address, gateway address and subnet mask. This is instead of going into Network connections -> Lan properties -> Internet protocol properties in windows. I know i can find the address using winsock. But how do i change it ?? Any suggestions , tips or tricks??

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Changing Ip adress, gateway & subnet mask of a connection

    You can change it using WMI classes. Take a look at this class. I believe most of what you want to do is taken care of here.
    http://msdn.microsoft.com/library/de...l/anch_wmi.asp
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  3. #3
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Changing Ip adress, gateway & subnet mask of a connection

    Welcome to VBF

    netsh is a great commandline tool.

    Just open a console and type "netsh"

    Using "?" on each command should help you through it.

    Although, for chnging this stuff programatically, WMI is a better way to go if you can make it work (it will be alot cleaner).

  4. #4
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Changing Ip adress, gateway & subnet mask of a connection

    this is an old post, but here is the WMI for changing to Static ..
    Includes IP, Subnet, Gateway, and DNS. Just leave out the DNS if you dont need it.

    VB Code:
    1. Sub Set_Static()
    2.     Dim objWMIService, colNetAdapters, objNetAdapter
    3.     Dim strIPAddress, strSubnetMask, strGateway, strGatewaymetric, strDNS
    4.     Dim errEnable, errGateways, errDNS
    5.     Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    6.     Set colNetAdapters = objWMIService.ExecQuery _
    7.         ("Select * from Win32_NetworkAdapterConfiguration " _
    8.             & "where IPEnabled=TRUE")
    9.     strIPAddress = Array("192.168.1.101")
    10.     strSubnetMask = Array("255.255.255.0")
    11.     strGateway = Array("192.168.1.1")
    12.     strGatewaymetric = Array(1)
    13.     strDNS = Array("10.10.10.10", "10.10.10.11")
    14.     For Each objNetAdapter In colNetAdapters
    15.         errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    16.         errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    17.         errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
    18.     Next
    19. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width