Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 842
  • Last Modified:

GetNetworkParams

I am having problems getting the GetNetworkParams() API Function. Does anyone have any example code for this api function?

Thanks for your help.

SohilM.
0
sohilm
Asked:
sohilm
  • 5
  • 3
  • 2
2 Solutions
 
Bob LearnedCommented:
What information are you trying to retrieve?

Bob
0
 
sohilmAuthor Commented:
The DNS Server List. I also need to get the gateway and mac address for the primary adapter. I understand that is in the getadaptersinfo() api call, but I haven't looked into it.

Thanks
Sohil M.
0
 
Bob LearnedCommented:
Are you talking about these settings from ipconfig /all:

Windows IP Configuration

        Host Name
        Primary Dns Suffix
        Node Type
        IP Routing Enabled
        WINS Proxy Enabled
        DNS Suffix Search List

Ethernet adapter Local Area Connection:

        Connection-specific DNS Suffix  
        Description
        Physical Address
        Dhcp Enabled
        Autoconfiguration Enabled
        IP Address
        Subnet Mask
        Default Gateway
        DHCP Server
        DNS Servers
        Primary WINS Server
        Lease Obtained
        Lease Expires

Bob
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Bob LearnedCommented:
VB.NET code to get MAC address and Gateway:

imports System
imports System.Management

Public Class WMICardGrab
Public Shared Sub Main()
Dim query as ManagementObjectSearcher = new _
ManagementObjectSearcher("SELECT * FROM
WIN32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'")
Dim queryCollection as ManagementObjectCollection = query.Get()
Dim mo as ManagementObject
For Each mo In queryCollection
Dim addresses() as string = CType(mo("IPAddress"), string())
Dim defaultgateways() as string = CType(mo("DefaultIPGateway"),
string())

Console.WriteLine("Network Card: {0}", mo("Description"))
Console.WriteLine(" MAC Address: {0}", mo("MACAddress"))

Dim ipaddress as string
For Each ipaddress In addresses
Console.WriteLine(" IP Address: {0}", ipaddress)
Next

Dim gateway as string
For Each gateway In defaultgateways
Console.WriteLine(" Gateway: {0}", gateway)
Next
Next
End Sub
End Class


Bob
0
 
sohilmAuthor Commented:
I need to use the api call, I can't use wmi. I don't have a guarantee that all these machines have wmi.
0
 
AgariciCommented:
here is the msdn link to GetNetworkParams:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getnetworkparams.asp
if you need help porting it to .net (and it seems this is the case) here is the vb.net version:
http://www.dotnet247.com/247reference/msgs/18/91898.aspx


hth,
A.
0
 
sohilmAuthor Commented:
I need it for C#, when I port it, I don't get an error value. The application just dies. Any ideas?
0
 
AgariciCommented:
if you post the code you use, maybe we can do some debugging...


hth,
A.
0
 
sohilmAuthor Commented:
I deleted the class. Let me see if I can rewrite it.
0
 
sohilmAuthor Commented:
Thanks for everyone's help. I ended up going with wmi, and just forced the users to have wmi setup.

Thanks
SohilM.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now