Jump to content

Get the IP of a certain network adapter


Recommended Posts

I am writing a script for a computer that has an ethernet adapter and also has the Cisco VPN (virtual adapter) installed. I need to figure out how to get the address of the VPN Adapter. I want a function only to run if the VPN is connected to a certain server. Running the script server side is not possible, so I need the client to check the VPN IP issued and run based on the netmask of that. Can anyone help?

BTW tried searching the forum, but wasn't sure how without using "ip". Search doesn't allow words less than three characters. So if this has been covered, I am sorry.

Thanks in advance for the help.

Vito

Link to comment
Share on other sites

I am writing a script for a computer that has an ethernet adapter and also has the Cisco VPN (virtual adapter) installed. I need to figure out how to get the address of the VPN Adapter. I want a function only to run if the VPN is connected to a certain server. Running the script server side is not possible, so I need the client to check the VPN IP issued and run based on the netmask of that. Can anyone help?

BTW tried searching the forum, but wasn't sure how without using "ip". Search doesn't allow words less than three characters. So if this has been covered, I am sorry.

Thanks in advance for the help.

Vito

to retrieve the public ip

#include <Inet.au3>
_GetIP()oÝ÷ ٩ݶ޶¸½ëaz*h~Ø^iÖ©¶ìºÇºÚ"µÍTYÜÌHÙÜHÝYÜTYÜÌÙÜHÙXÛÛYÜTYÜÌÈÙÜHYÜTYÜÍÙÜHÝYÜ
Link to comment
Share on other sites

What if the adapters are not the same on every box?

What if one person has an extra adapter (maybe wireless card) installed and enabled. How can I be sure that I get the address of the VPN Adapter? Do I need to poll every IP looking for the correct netmask?

Link to comment
Share on other sites

I did this:

<CODE>

$ip1 = StringLeft(@IPAddress1, 7)

$ip2 = StringLeft(@IPAddress2, 7)

$ip3 = Stringleft(@IPAddress3, 7)

$ip4 = StringLeft(@IPAddress4, 7)

If $ip1 = "160.132" Or $ip2 = "160.132" Or $ip3 = "160.132" Or $ip4 = "160.132" Then

MsgBox(0, "success", "It werkz")

Else

MsgBox(0, "failed", "you are the lamest coder ever")

EndIf

</CODE>

Maybe not the most elegant way, but can you see any problems it might cause?

Link to comment
Share on other sites

One problem that I see right off is - what if there are more than 4 network adapters?

But this may be one of those situations where you can accept failure in a very small percentage of systems... it just depends on the criticality of the code.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

more than 4... :rolleyes:

Try this code:

;by A. Percy -> Alexsandro Percy

#include <array.au3>

$AdapterList = GetAdaptersList( )
_ArrayDisplay( $AdapterList )

Exit

;------------------------------------------------------------------------------------------------------------
Func GetAdaptersList( $ListAll = 0 )
    Local $Cols = 5
    Local $Adapters[1][$Cols]
    $Adapters[0][0] = 0
    
    If @OSTYPE = "WIN32_NT" Then
        ;Use WMI
        Local $o_WMIService = ObjGet( "winmgmts:\\" & @ComputerName & "\root\cimv2" )
        Local $Query = "SELECT Index, Caption, MACAddress, IPAddress, DefaultIPGateway FROM Win32_NetworkAdapterConfiguration"
        If $ListAll = 0 Then
            $Query &= " Where IPEnabled = True"
        EndIf
        Local $o_Adapters = $o_WMIService.ExecQuery( $Query, "WQL", 0x30 )
        If IsObj( $o_Adapters ) Then
            Local $o_Adapter
            For $o_Adapter In $o_Adapters
                $Adapters[0][0] += 1
                ReDim $Adapters[UBound($Adapters) + 1][$Cols]
                $Adapters[$Adapters[0][0]][0] = $o_Adapter.Index                        ;index
                $Adapters[$Adapters[0][0]][1] = $o_Adapter.Caption                      ;adapter name
                $Adapters[$Adapters[0][0]][2] = $o_Adapter.MACAddress                   ;adapter real mac address
                $Adapters[$Adapters[0][0]][3] = $o_Adapter.IPAddress(0)                 ;IP
                $Adapters[$Adapters[0][0]][4] = $o_Adapter.DefaultIPGateway(0)          ;Default Gateway
            Next
        EndIf
    EndIf
    return $Adapters
EndFunc

;------------------------------------------------------------------------------------------------------------
#cs
from Microsoft Developer Network:

class Win32_NetworkAdapterConfiguration : CIM_Setting
{
  boolean ArpAlwaysSourceRoute;
  boolean ArpUseEtherSNAP;
  string Caption;
  string DatabasePath;
  boolean DeadGWDetectEnabled;
  string DefaultIPGateway[];
  uint8 DefaultTOS;
  uint8 DefaultTTL;
  string Description;
  boolean DHCPEnabled;
  datetime DHCPLeaseExpires;
  datetime DHCPLeaseObtained;
  string DHCPServer;
  string DNSDomain;
  string DNSDomainSuffixSearchOrder[];
  boolean DNSEnabledForWINSResolution;
  string DNSHostName;
  string DNSServerSearchOrder[];
  boolean DomainDNSRegistrationEnabled;
  uint32 ForwardBufferMemory;
  boolean FullDNSRegistrationEnabled;
  uint16 GatewayCostMetric[];
  uint8 IGMPLevel;
  uint32 Index;
  uint32 InterfaceIndex;
  string IPAddress[];
  uint32 IPConnectionMetric;
  boolean IPEnabled;
  boolean IPFilterSecurityEnabled;
  boolean IPPortSecurityEnabled;
  string IPSecPermitIPProtocols[];
  string IPSecPermitTCPPorts[];
  string IPSecPermitUDPPorts[];
  string IPSubnet[];
  boolean IPUseZeroBroadcast;
  string IPXAddress;
  boolean IPXEnabled;
  uint32 IPXFrameType[];
  uint32 IPXMediaType;
  string IPXNetworkNumber[];
  string IPXVirtualNetNumber;
  uint32 KeepAliveInterval;
  uint32 KeepAliveTime;
  string MACAddress;
  uint32 MTU;
  uint32 NumForwardPackets;
  boolean PMTUBHDetectEnabled;
  boolean PMTUDiscoveryEnabled;
  string ServiceName;
  string SettingID;
  uint32 TcpipNetbiosOptions;
  uint32 TcpMaxConnectRetransmissions;
  uint32 TcpMaxDataRetransmissions;
  uint32 TcpNumConnections;
  boolean TcpUseRFC1122UrgentPointer;
  uint16 TcpWindowSize;
  boolean WINSEnableLMHostsLookup;
  string WINSHostLookupFile;
  string WINSPrimaryServer;
  string WINSScopeID;
  string WINSSecondaryServer;
};
#ce

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...