Networking Forums

Networking Forums > Computer Networking > Windows Networking > How to configure a subnet with code?

Reply
Thread Tools Display Modes

How to configure a subnet with code?

 
 
ccc
Guest
Posts: n/a

 
      09-15-2004, 06:01 AM
Can you give me a huge help on this? I want to programmatically set up a subnet.

Thanks.

The Clueless Pooh
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmVybmQgS3JldXppbmdlcg==?=
Guest
Posts: n/a

 
      09-15-2004, 11:19 AM
Where?!

"ccc" wrote:

> Can you give me a huge help on this? I want to programmatically set up a subnet.
>
> Thanks.
>
> The Clueless Pooh
>

 
Reply With Quote
 
ccc
Guest
Posts: n/a

 
      09-15-2004, 07:37 PM
On XP systems. Currently I have to go into network, select TCP/IP,
properties, and use static IP, and give it the subnet
255.255.255.0..etc. Can I program this in instead?
If I am still not being clear, please let me know.
 
Reply With Quote
 
Bill Grant
Guest
Posts: n/a

 
      09-15-2004, 11:34 PM
Can't you use DHCP?

"ccc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> On XP systems. Currently I have to go into network, select TCP/IP,
> properties, and use static IP, and give it the subnet
> 255.255.255.0..etc. Can I program this in instead?
> If I am still not being clear, please let me know.



 
Reply With Quote
 
=?Utf-8?B?QmVybmQgS3JldXppbmdlcg==?=
Guest
Posts: n/a

 
      09-16-2004, 10:55 AM
Hello,

you can try the command netsh in a batch-file like this:

Here you need to set a complete ip-configuration

netsh interface ip set address [name=]Interfacename [source=]{dhcp | static
[addr=]IP-Adress [mask=]Subnetmask [gateway=]{none | Standardgateway

[[gwmetric=]Gatewaymetrik]}}

example:
netsh interface ip set address network static addr=192.168.0.233
mask=255.255.255.0 gateway=none


You can also script it with vbs like this:
-----------------------------------------------------------------
Returns the IP address for each IP-enabled network adapter installed in a
computer.
Script Code :
---------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration where
IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
-----------------------------------------------------------------

and than you can take the ip-adress-info and the new subnet-mask to change
the ip-configuration like that

-----------------------------------------------------------------
Sets the IP address of a computer to 192.168.1.141, and sets the IP gateway
to 192.168.1.100.
Script Code :
-----------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
-----------------------------------------------------------------

Good luck
Bernd

"ccc" wrote:

> On XP systems. Currently I have to go into network, select TCP/IP,
> properties, and use static IP, and give it the subnet
> 255.255.255.0..etc. Can I program this in instead?
> If I am still not being clear, please let me know.
>

 
Reply With Quote
 
ccc
Guest
Posts: n/a

 
      09-16-2004, 04:03 PM
Thanks, that would get me started.

1) I am actually using Perl, do you know of the perl equivalent of
this? or C++. I don't know VB.

2) I only want to set network adapter of linksys, how do I filter that
out?

I noticed that in the
local machine/system/currentcontrolset/Services/Tcpip/Paramesters/Interfaces

There list a few interfaces, and there are fields like 'IP Address'
and 'subnet mask', can I just change here? Well, this still runs into
the problem of knowing which interface to set.

So question that I like to repeat and please help me on this:
How to get the text string of the network connections?

I.e. In my network connections, I have an icon of "Local Area
Connection", it is enabled and Linksys. How do I get that info, in
particular I want to get teh string of "Local Area Connection" and
"Linksys" since I want to know which connection is on which brand of
network adapter.

Hope this is not too confusing.. Please help.

Thanks.
 
Reply With Quote
 
=?Utf-8?B?QmVybmQgS3JldXppbmdlcg==?=
Guest
Posts: n/a

 
      09-17-2004, 04:55 AM
I have not the ability to tell you the script in Perl.....

This script will show you the adapters and their configuration on your
computer
----------------------------------------------------------------------------------
WMI script that returns configuration data similar to that returned by
Ipconfig.
Script Code
----------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

n = 1
WScript.Echo

For Each objAdapter in colAdapters
WScript.Echo "Network Adapter " & n
WScript.Echo "================="
WScript.Echo " Description: " & objAdapter.Description

WScript.Echo " Physical (MAC) address: " & objAdapter.MACAddress
WScript.Echo " Host name: " & objAdapter.DNSHostName

If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
WScript.Echo " IP address: " & objAdapter.IPAddress(i)
Next
End If

If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
WScript.Echo " Subnet: " & objAdapter.IPSubnet(i)
Next
End If

If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
WScript.Echo " Default gateway: " & _
objAdapter.DefaultIPGateway(i)
Next
End If

WScript.Echo
WScript.Echo " DNS"
WScript.Echo " ---"
WScript.Echo " DNS servers in search order:"

If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
WScript.Echo " " & objAdapter.DNSServerSearchOrder(i)
Next
End If

WScript.Echo " DNS domain: " & objAdapter.DNSDomain

If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
WScript.Echo " DNS suffix search list: " & _
objAdapter.DNSDomainSuffixSearchOrder(i)
Next
End If

WScript.Echo
WScript.Echo " DHCP"
WScript.Echo " ----"
WScript.Echo " DHCP enabled: " & objAdapter.DHCPEnabled
WScript.Echo " DHCP server: " & objAdapter.DHCPServer

If Not IsNull(objAdapter.DHCPLeaseObtained) Then
utcLeaseObtained = objAdapter.DHCPLeaseObtained
strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained = ""
End If
WScript.Echo " DHCP lease obtained: " & strLeaseObtained

If Not IsNull(objAdapter.DHCPLeaseExpires) Then
utcLeaseExpires = objAdapter.DHCPLeaseExpires
strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires = ""
End If
WScript.Echo " DHCP lease expires: " & strLeaseExpires

WScript.Echo
WScript.Echo " WINS"
WScript.Echo " ----"
WScript.Echo " Primary WINS server: " & objAdapter.WINSPrimaryServer
WScript.Echo " Secondary WINS server: " & objAdapter.WINSSecondaryServer
WScript.Echo

n = n + 1

Next

Function WMIDateStringToDate(utcDate)
WMIDateStringToDate = CDate(Mid(utcDate, 5, 2) & "/" & _
Mid(utcDate, 7, 2) & "/" & _
Left(utcDate, 4) & " " & _
Mid (utcDate, 9, 2) & ":" & _
Mid(utcDate, 11, 2) & ":" & _
Mid(utcDate, 13, 2))
End Functio
----------------------------------------------------------------------------------





"ccc" wrote:

> Thanks, that would get me started.
>
> 1) I am actually using Perl, do you know of the perl equivalent of
> this? or C++. I don't know VB.
>
> 2) I only want to set network adapter of linksys, how do I filter that
> out?
>
> I noticed that in the
> local machine/system/currentcontrolset/Services/Tcpip/Paramesters/Interfaces
>
> There list a few interfaces, and there are fields like 'IP Address'
> and 'subnet mask', can I just change here? Well, this still runs into
> the problem of knowing which interface to set.
>
> So question that I like to repeat and please help me on this:
> How to get the text string of the network connections?
>
> I.e. In my network connections, I have an icon of "Local Area
> Connection", it is enabled and Linksys. How do I get that info, in
> particular I want to get teh string of "Local Area Connection" and
> "Linksys" since I want to know which connection is on which brand of
> network adapter.
>
> Hope this is not too confusing.. Please help.
>
> Thanks.
>

 
Reply With Quote
 
ccc
Guest
Posts: n/a

 
      09-20-2004, 05:25 PM
Hi,
Trying to read your VB code, I don't know VB, how do I determine, say
the system has two network adapters, I only want to set the subnet for
a particular one.

I.e. Brand AAAA and BBBB. AAAA is the one I want to create subnet and
assign IP address to.

If you can respond in C++ that would be awesome.

Thanks for your help.
Pooh
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Routing - Computers on either subnet have problems finding PCs on the other subnet ZZYZX Windows Networking 2 03-26-2011 01:01 AM
VPN Clients and subnet, NOT the usual "255.255.255.255 subnet mask" question! snowdog_2112 Windows Networking 4 09-09-2006 01:35 AM
How to get a MAC code? Richard Kennaway Broadband 5 03-06-2006 06:32 PM
subnet to subnet routing question S James Linux Networking 0 09-04-2003 03:37 PM
firewall/router - subnet/router - subnet S James Linux Networking 0 09-04-2003 01:17 PM



1 2 3 4 5 6 7 8 9 10 11