Page 1 of 1

IP adress

Posted: Thu Oct 11, 2018 2:59 am
by Noubissi
Hello everyone,
I just set up a script to provide all the information of a computer (see script). the script works very well, it goes back all the information of the machine (IP) when it is a question of executing it on a desktop. For remote users (laptop) use a 3G chip finally to connect via VPN on the network of our company, the script goes back the IP of the 3G chip. the goal is to make sure when using the VPN, the script must return the IP of the VPN and not that of 3G.
after several tests, I can not do it. could you help me ?
thank you

Code: Select all

Add-Type -AssemblyName presentationframework
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase
#[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')


#Chargement de la vue
$XamlLoader = (New-Object System.Xml.XmlDocument)
$XamlLoader.Load((get-location).path + "\layout.xaml")
$XamlMainWindow = $XamlLoader
$Reader = (New-Object System.Xml.XmlNodeReader $XamlMainWindow)
$Form = [Windows.Marku[Codebox=powershell file=Untitled.ps1]p[/Codebox].XamlReader]::Load($Reader)

#Nom de l'ordinateur
$computerName = $Form.findname("computerName")
$computerName.Content = $env:computername

#Adresses IP
$ip1 = $Form.findname("ip1")
$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.IPAddress -ne $null})
$ip1.Content = $(($ip | select-object -first 1).ipaddress[0])

#Passerelle
$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.IPAddress -ne $null})
$gateway = $Form.findname('gateway')
$gateway.Content = $(($ip | select-object -first 1).DefaultIpGateway[0])

#Adresses MAC
$mac1 = $Form.findname('mac1')
# $mac2Txt = $Form.findname('mac2')
$mac=(Get-WmiObject win32_networkadapterconfiguration | select macaddress | where {$_.macaddress -ne $null})
#SLE/Debug $mac1 = $mac[0].macaddress
# $mac2 = $mac[1].macaddress
#SLE/Debug $mac1.Content = $mac1
$mac1.Content = $mac[0].macaddress
# $mac2Txt.Text = $mac2

#Domaine
$domain = $Form.findname('domain')
$domain.Content = $env:USERDOMAIN

#Serveur de connexion
$coServer = $form.findname('coServer')
$coServer.Content = $env:logonserver

#Version système d'exploitation
$osVersionTxt = $Form.findname('os')
$os = Get-WmiObject -class Win32_OperatingSystem
$osName=$os.Caption
$osSp=$os.ServicePackMajorVersion
#SLE/Debug $os.Content = $osName + ' Service Pack ' + $osSp
$osVersionTxt.Content = $osName + ' Service Pack ' + $osSp

#Numéro série PC
$pcSerial = $Form.findname('pcSerial')
$pcSerial.Content = (gwmi win32_bios).serialnumber

#Version internet explorer
$ieVersion = $Form.findname('ieVersion')
$ieVersion.Content = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet Explorer').svcVersion

#Utilisateur connecté localement
$user = $Form.findname('user')
$user.Content = $env:UserName

#Dernier boot
$lastBoot = $Form.findname('lastBoot')
$date=Get-WmiObject win32_operatingsystem | select csname, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
$lastBoot.Content = $date.lastbootuptime

#Mémoire physique
$memory = $Form.findname('memory')
$bytes = (Get-WmiObject -class "cim_physicalmemory" | Measure-Object -Property Capacity -Sum).Sum
$mb = $bytes / 1024 / 1024
$mb = 
$memory.Content = $mb.tostring() + ' MB'

#Espace libre disques durs
$hdd = $Form.findname('hdd')
$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object FreeSpace
$freeSpace = [Math]::Round($Disk.Freespace / 1GB, 2)
$hddFormat = (GET-WMIOBJECT -query "select * from win32_logicaldisk where drivetype =3" | select *).filesystem
$hddName = (GET-WMIOBJECT -query "select * from win32_logicaldisk where drivetype =3" | select *).caption
$hdd.Content = $hddName + '\ ' + $freeSpace + ' GB ' + $hddFormat

#Numéro de la hotline
$hotline = $Form.findname('hotline')
$hotline.Content = '01 69 93 11 76'

#Modèle du PC
$model = $Form.findname('model')
$infosPC = Get-CimInstance -ClassName Win32_ComputerSystem
$model.content = $infosPC.Model

$Form.ShowDialog() | out-null 


Re: IP adress

Posted: Thu Oct 11, 2018 3:14 am
by jvierra
You code has nothing to do with networking or with a VPN. It is a WPF form. Start by executing the code to get the adapter configuration at a prompt. Once you have this worked out then you can move it to the WPF form.

Finding the VPN will depend on you researching to see what the VPN name is. You will then use the VPN name to return the VPN adapter configuration.

Re: IP adress

Posted: Thu Oct 11, 2018 3:21 am
by Noubissi
sorry I do not understand well. without the 3G chip, the IP goes back well. but with the 3G chip, instead of providing the IP assign the IP provided by the VPN via pulseSecure, it gives the ip of the 3G key

Re: IP adress

Posted: Thu Oct 11, 2018 3:41 am
by jvierra
You will have to contact the vendor of the 3G chip/adapter as it may be set up much differently than a normal adapter. You want to VPN adapter and not the chip. You need to search for and reference the VPN that has been established.