Page 1 of 1 1
Topic Options
#12037 - 2001-08-31 09:24 PM Comparison
Anonymous
Unregistered


Hi again.

I'm presently making a script to detect the IP adress of a VPN address.

When KIX detects The same IP adress and the same gateway in a ipconfig /all command, it conclude that the IP are the same and can know that this is the VPN adress and not the other IP adresses.

Here is my question:
this test txt file.

IP Address. . . . . . . . . : 192.168.0.53
Subnet Mask . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . : 192.168.0.53

The IP and Gateway are the same.

I run my code and KIX correctly detect both addresses (192.168.0.53) but he always thinks that they are different when comparing.

What have i done wrong?

Here is my script:


; ******* Utilitaire pour détecter l'adresse IP d'un VPN ***
; ************** Partie 1 ******************
; *** Détection de la langue du Ipconfig ***

$tempfile = "c:\ipconfig.txt"
shell "%comspec% /c ipconfig /all > $tempfile"
$ = Open (1,"$tempfile")
while @error = 0
$x=readline(1)
if instr($x,"IP Address")
$ = close (1)
goto english
else
if instr($x,"Adresse IP")
$ = close (1)
goto francais
else
endif
endif
loop
goto error
; ************** Partie 2 ******************
; *** Détection de l'adresse VPN Anglais ***
:english
$ = Open (1,"$tempfile")
:again
do
$y = readline (1)
? "$y"
if instr($y,"IP address")
$IP = substr($y, instr($y,":")+2, 16)
? "$IP"
$y = readline (1)
$y = readline (1)
$Gate = substr($y, instr($y,":")+2, 16)
? "$gate"
? " if $IP = $gate "
if '$IP' = '$gate'
goto VPNaddress
else
goto again
endif
endif
until @error <> 0
goto error

; ************** Partie 3 ******************
; *** Détection de l'adresse VPN Francais ***
:francais
? "francais"
goto end

; ************** Partie 4 ******************
; *** Ipconfig ne donne aucune adresse ou ***
; ************ fonctionne mal **************
:error
? " Vous n'avez pas d'adresse valide"
goto end


:VPNaddress
" Voici l'adresse VPN c'est $IP"
:end
$ = close (1)
DEL $tempfile

Thank you

Frédéric Giguère

Top
#12038 - 2001-09-01 02:07 AM Re: Comparison
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I single-stepped through your script and the problem is that after reading and verifying the line with the IP address, you count lines rather than verify the GW line. You are in fact not reading in the GW line but rather the Mask line, so you're comparing the wroong items.
quote:

IP Address. . . . . . . . . . . . : 10.198.51.6
10.198.51.6

Subnet Mask . . . . . . . . . . . : 255.255.255.255
255.255.255.255
if 10.198.51.6 = 255.255.255.255


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12039 - 2001-09-01 03:15 AM Re: Comparison
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Further on this...
By opening the IPCONFIG.TXT file in an editor that shows the hex codes, you can see why your line counting is off.
code:

09 49 50 20 41 64 64 72 65 73 73 2E 20 2E 20 2E IIP Address. . .
20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E . . . . . . . .
20 2E 20 3A 20 31 30 2E 31 39 38 2E 35 31 2E 36 . : 10.198.51.6
0D 0A MJ
0D 0A MJ
09 53 75 62 6E 65 74 20 4D 61 73 6B 20 2E 20 2E ISubnet Mask . .
20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E . . . . . . . .
20 2E 20 3A 20 32 35 35 2E 32 35 35 2E 32 35 35 . : 255.255.255
2E 32 35 35 0D 0A .255MJ
0D 0A MJ
09 44 65 66 61 75 6C 74 20 47 61 74 65 77 61 79 IDefault Gateway
20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E 20 2E . . . . . . . .
20 2E 20 3A 20 31 30 2E 31 39 38 2E 35 31 2E 36 . : 10.198.51.6
0D 0A MJ
0D 0A MJ

[ 01 September 2001: Message edited by: LLigetfa ]

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12040 - 2001-09-02 02:03 AM Re: Comparison
Anonymous
Unregistered


Hi Lligetfa,
I think you are wrong in your first affirmation when you say that i don't get the good line. I know that they are the good lines since i use ? "$IP" and ? "$gate" to see what are the result. Everytime, i get 192.168.0.53 for both of them as it should.
I know too that ipconfig always put the gateway adrress two lines after the IPadress in all times. I never saw it differently in my tests.

About your second note, i never saw ipconfig show me a file like yours. I use the DoS version of windows 98 in my tests. Do you use a different one? Did you use a particular option with Ipconfig?

Thank you Llifetga for your help,

Frédéric



Top
#12041 - 2001-09-02 04:04 AM Re: Comparison
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Sorry to disappoint...
I tested on Win2k. In my case, as you can see IPCONFIG output has extra 0D,0A.
Using your code with two extra '$y = readline (1)', the results are as expected. I added '? IP = Gate' in place of your 'goto VPNaddress'
code:

10.198.54.249
10.198.54.249
if 10.198.54.249 = 10.198.54.249
IP = Gate


The content of IPCONFIG.TXT is as follows:
code:


Windows 2000 IP Configuration

Host Name . . . . . . . . . . . . : 999-51-566
Primary DNS Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No


Ethernet adapter Local Area Connection:

Media State . . . . . . . . . . . : Cable Disconnected

Description . . . . . . . . . . . : 3Com EtherLink XL 10/100 PCI For Complete PC Management NIC (3C905C-TX)
Physical Address. . . . . . . . . : 00-50-DA-68-9A-06


PPP adapter My Office:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface

Physical Address. . . . . . . . . : 00-53-45-00-00-00

DHCP Enabled. . . . . . . . . . . : No

IP Address. . . . . . . . . . . . : 10.198.54.249

Subnet Mask . . . . . . . . . . . : 255.255.255.255

Default Gateway . . . . . . . . . : 10.198.54.249

DNS Servers . . . . . . . . . . . : 10.198.10.1
10.198.10.18
Primary WINS Server . . . . . . . : 10.198.10.1

Secondary WINS Server . . . . . . : 10.198.10.18



BTW, I ran this interactive on KIX 3.62 and not from logon. I notice you count 16 in 'substr($y, instr($y,":")+2, 16)' but in your case there are fewer than 16 chars in IP. Check your IPCONFIG.TXT file to see if there are hidden trailing chars that would make compare false.

[ 02 September 2001: Message edited by: LLigetfa ]

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12042 - 2001-09-04 04:15 PM Re: Comparison
Anonymous
Unregistered


I will get a look at that.

Thank you very much Les

Top
#12043 - 2001-09-04 07:09 PM Re: Comparison
Anonymous
Unregistered


You might try this to get the information you need. WMI seems easier to use for me

break on

$IpSet = GetObject("winmgmts:").ExecQuery("select DefaultIPGateway from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

IF @error <> 0
? @error + " / " @serror
else
For Each $IPConfig In $IPSet

$GATEWAY = $IPConfig.DefaultIPGateway(0)

Next
EndIf

Top
#12044 - 2001-09-06 03:56 PM Re: Comparison
Anonymous
Unregistered


Les i found the problem,

The IP address line had a tab at the end that
the gateway address didnt had.

When i removed it, i was able to do my comparison with no problem.

So much time for such a simple thing!

Fred

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 885 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.051 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org