Sign in to follow this  
Followers 0
rayven

Help with Coding an IP Detection Script

7 posts in this topic

Hello AutoIt community,

I'm coding a script to detect a public and Lan IP address. While the script does work using MsgBox, I wanted to create a way to have people copy the result of the 2 IP addresses from a read-only edit box instead.

I can attach the script if need be or paste it so you can see my code. Please advise what would work best, as I'm new here and don't know the software that you all use. How do you all show AutoIt code in posts?

Thanks.

IPDetect-V1.0.au3

Share this post


Link to post
Share on other sites



rayven,

Welcome to the AutoIt forum. :)

You can get the pretty syntax colours and code box by putting [autoit] before and [/autoit] after your posted code. ;)

To get a read-only edit, you need to create it yourself - like this:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Compile_Both=y
    #AutoIt3Wrapper_UseX64=y
    #AutoIt3Wrapper_Res_Comment=IP Detector Created July 11, 2011 9:00 AM -0400 EDT. Last updated January 27th, 2012 11:05 -0500 EST.
    #AutoIt3Wrapper_Res_Description=IP Detector For Windows
    #AutoIt3Wrapper_Res_Fileversion=1.0
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
    #AutoIt3Wrapper_Res_LegalCopyright=Copyright 2012 Daniel Chavez
    #AutoIt3Wrapper_Res_SaveSource=y
    #AutoIt3Wrapper_Res_Language=1033
    #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
    #AutoIt3Wrapper_Add_Constants=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
    #All original copyright notices must stay intact regardless of modifications!!!!!
    #Program License
    #This program is licensed under the GPL open-source styled license. Please see below for further information.
    #IP Detect Detecting a public/Lan IP address
    #Copyright © 2012 Daniel Chavez
    #This program is free software; you can redistribute it and/or
    #modify it under the terms of the GNU General Public License
    #as published by the Free Software Foundation; either version 2
    #of the License, or (at your option) any later version.
    #This program is distributed in the hope that it will be useful,
    #but WITHOUT ANY WARRANTY; without even the implied warranty of
    #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #GNU General Public License for more details.
    #You should have received a copy of the GNU General Public License
    #along with this program; if not, write to the Free Software
    #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    #Or contact topdog2046@gmail.com via email to receive a copy.
#ce
;This is Version 1.0 of IP Detect
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <Inet.au3>
$hGUI = GUICreate("Welcome To IP Detect: Version 1.0", 300, 200)
GUISetState()
Sleep(3000)
;Run through diagnostics
;Check system CPU to see if we are running on 32 or 64 bit and report to the user the CPU arch, not that it'd matter anyway. Also include OS version and computer name.
TrayTip("Running Diagnostics", " Checking CPU architecture, OS, and computer name  we are running on. One moment.", 15, 1)
;Sleep(5000)
MsgBox(0, "OS Version, CPU architecture, and computer name", "OS is :" & @OSVersion & @CRLF & "CPU architecture is :" & @CPUArch & @CRLF & "You are running under computer name :" & @ComputerName, 0)
MsgBox(0, "Internet Required", "This program requires internet access. Please insure you have internet access available before running this program.", 5)
TrayTip("Checking Admin Permissions", "Checking For Admin level permissions. One moment.", 15, 1)
Sleep(3000)
If IsAdmin() Then MsgBox(0, "Administrative Check", "Admin rights detected", 6)

SoundSetWaveVolume(15)
SoundPlay("wait.mp3", 0)
ToolTip("Gathering your Public and Lan IP addresses.", 0, 0, "Checking for existing IP Addresses. Checking network adapters ... Connecting to internet ...", 0)
;Sleep(9000)
$PublicIP = _GetIP()
If @error = 1 Then
    MsgBox(0, "Connection Error", "No internet access could be found. Please make sure internet is available before re-running the program.", 6)
    Exit;
EndIf
If @error = 0 Then

    GUICtrlCreateLabel("IP Addresses detected" & @CRLF & @CRLF & "The following were the IP addresses we found on your system.", 10, 10, 280, 20)
    $sText = "Public: " & $PublicIP & @CRLF & @CRLF & "Lan: " & @IPAddress1 & @CRLF & @CRLF
    GUICtrlCreateEdit($sText, 10, 30, 280, 70, $ES_READONLY)
    GUICtrlCreateLabel("This information has been copied to the clipboard." & @CRLF & "You may dismiss this box by pressing OK", 10, 120, 280, 40)
    $hButton = GUICtrlCreateButton("OK", 210, 160, 80, 30)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hButton
                GUIDelete($hGUI)
                ExitLoop
        EndSwitch
    WEnd
EndIf
ClipPut($PublicIP & @CRLF & @IPAddress1)
Exit;

You will see I also moved the #include <Inet.au3> line to the top of the script. When you use #include files they are put into the script at the point you call them - the middle of the script is not usually a good place. :)

As a relative newcomer to AutoIt, you might like to look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page).

Good luck - and please ask if you have any questions. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is there anyway that I can, somehow have the script write instead of a readonly edit box, write an edit box with the below code, but disable the box's contents from being edited?

"Public IP:" & @CRLF & $PublicIP & @CRLF
"Lan:" & @CRLF & @IPAddress1 & @CRLF

The reason I ask is because I'm coding this for those whom have vision impairments such as myself, who use screen readers. And the code that was shown to me, when the IP addresses are gotten, the user has no idea that the IP addresses are even available in the edit box because nothing comes up with IP Detection results, or at least some type of feedback that the IP addresses are ready to be seen in the edit box.

Edited by rayven

Share this post


Link to post
Share on other sites

rayven,

instead of a readonly edit box, write an edit box [...] but disable the box's contents from being edited?

Not that I know of - "read-only" means "read-only" and that is what you get. If I understand correctly, you need domething to signal the arrival of the IPs in the edit box - would a quick MsgBox or ToolTip be any use? That would be easy enough to code and would leave the current edit there to be selected when the user was ready. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba23,

i found your code really useful for me. But i have a question, what if a computer with more than 2 network interface (my PC have 2 network adapter + VMWare virtual interface). How i can pick a interface with internet access?

Here all my PC network interface:

PS C:UsersAdministrator> netsh int ip show int
Idx  Met         MTU          State             Name
---  ----------  ----------  ------------  ---------------------------
  1       50  4294967295  connected  Loopback Pseudo-Interface 1
36         5        1500  connected  ADSL
32         5        1500  connected  Local Area Connection 6
34         5        1500  connected  Local Area Connection 7
19        10        1500  disconnected  Local Area Connection* 16
30         5        1500  connected  Local Area Connection 4
31         5        1500  connected  Local Area Connection 5

Sicay

Share this post


Link to post
Share on other sites

tonlo,

I have no idea. I suggest you start a new thread as your question has littel to do with the posts above and will probably be ignored by passers by. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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