Sign in to follow this  
Followers 0
bang1902

Function Ping

8 posts in this topic

Hi all,

I use function Ping, I have a problem:

Ping IP add: 192.168.1.1 -> result: good

Ping IP add: 192.168.001.001 -> result: not reach able.

I ping 192.168.001.001 because I use Function FileRead ( "filehandle/filename" [, count] ) to get IP add in the text file with count = 15

Help me.

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

this would remove leading zeroes from an IP address

$str = "192.168.001.001"

$strArray = stringsplit($str , "." , 2)

for $i = 0 to ubound($strArray) - 1
If stringleft($strArray[$i] , 1) = "0" Then
$strArray[$i] = stringtrimleft($strArray[$i] , 1)
If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1)
Endif
next

$str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3]

msgbox (0, '' , $str)
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here another method:

$sIP = "192.168.001.001"

MsgBox(0, "Test", ReformatIP($sIP))

Func ReformatIP($sIP)
    Local $aTmp = StringSplit($sIP, ".", 2)
    Return StringFormat("%-0d.%-0d.%-0d.%-0d", $aTmp[0], $aTmp[1], $aTmp[2], $aTmp[3])
EndFunc

Why did you post it here (ActiveX/COM Help and Support (AutoItX))?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

this would remove leading zeroes from an IP address

$str = "192.168.001.001"

$strArray = stringsplit($str , "." , 2)

for $i = 0 to ubound($strArray) - 1
If stringleft($strArray[$i] , 1) = "0" Then
$strArray[$i] = stringtrimleft($strArray[$i] , 1)
If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1)
Endif
next

$str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3]

msgbox (0, '' , $str)

Thanks, I think that you right.

Share this post


Link to post
Share on other sites

Here another method:

$sIP = "192.168.001.001"

MsgBox(0, "Test", ReformatIP($sIP))

Func ReformatIP($sIP)
Local $aTmp = StringSplit($sIP, ".", 2)
Return StringFormat("%-0d.%-0d.%-0d.%-0d", $aTmp[0], $aTmp[1], $aTmp[2], $aTmp[3])
EndFunc

Why did you post it here (ActiveX/COM Help and Support (AutoItX))?

Br,

UEZ

Thanks. I will post it later.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <File.au3>

global $line = _FileCountLines("ipadd.txt")

;MsgBox (0, "so dong:", $line)

for $j = 1 to 5 +1

for $k = 1 to $line +1

$str = FileReadLine ("ipadd.txt",$k)

If @error = -1 Then ExitLoop

$strArray = stringsplit($str , "." , 2)

for $i = 0 to ubound($strArray) - 1

If stringleft($strArray[$i] , 1) = "0" Then

$strArray[$i] = stringtrimleft($strArray[$i] , 1)

If stringleft($strArray[$i] , 1) = "0" Then $strArray[$i] = stringtrimleft($strArray[$i] , 1)

Endif

next

$str = $strArray[0] & "." & $strArray[1] & "." & $strArray[2] & "." & $strArray[3]

;msgbox (0, '' , $strArray[4])

Local $var = Ping($str,2500)

If $var Then; also possible: If @error = 0 Then ...

;MsgBox(0, "Status", "Online, roundtrip was:" & $var)

Else

$time = @hour & ":" & @MIN &"---"& @MDAY &"/"& @MON &"/"& @YEAR

local $file

$file = FileOpen ("results.txt", 1)

$data = & "Unreachable to: " $str & "--NE--" & $strArray[4] & " at: " & $time & @CRLF

FileWrite ($file, $data)

FileClose($file)

Beep (3000)

MsgBox(0, "Status", "Unreachable to: " & $str & "--NE--" & $strArray[4] &"---Error: " & @error, 5)

EndIf

Sleep(2000)

Next

Sleep (3000)

Next

This is my code ($strArray[4] added to explain for ip add, this is name of host). Now, I writing GUI for it. And I meet a problem about function button. I'll read more. If I need to help, I question continue.

Edited by bang1902

Share this post


Link to post
Share on other sites

Hi all, I has a different method:

$strArray[$i] = Number($strArray[$i])

Share this post


Link to post
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
Sign in to follow this  
Followers 0