Forum Discussion

jackson_1's avatar
jackson_1
Frequent Contributor
15 years ago

how to get the computer IP Address via Computer Name

hi all,

i want to get the specified computer IP address via the computer name in my delphi script project!

how to do this?



Thanks very much!!!

6 Replies

  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    hi alex,



    can you give me an example with delphi script.





    Thanks very much!

  • Hi Du,





    We will create the needed script, publish it in the How To section of our web site and post a link to it here.


  • VLapidus's avatar
    VLapidus
    Frequent Contributor
    Hi,



    You can use the example from the link:

    http://smartbear.com/support/viewarticle/8963/



    In the code, you need to modify the Test function:



    contents := 'Execution result: ' + ExecAndWaitForEnd('ping', 'ComputerName'));

    Then, you will be able to extract the Ip from the contents

    function ParseIP(TextOutput);

      var


        MyRegExp: OleVariant;


        ResStr: String;


    begin


      MyRegExp:=HISUtils.RegExpr;


      ResStr:='';


     
    MyRegExp.Expression:='(\d{1,3}\.){3}\d{1,3}';


      if
    MyRegExp.Exec(TextOutput) then


        ResStr :=
    MyRegExp.Match[0];


      result := ResStr; 


    end;



  • jackson_1's avatar
    jackson_1
    Frequent Contributor
    hi;

    i am done this scripts. share it there.

    function ResolveIP(ComputerName): string;


     


    var

        objShell,objExec,RegEx;

    var

        StrOutput: string;

       

    begin


        objShell: = Sys.OleObject['WScript.Shell'];

        objExec: = objShell.Exec('Ping ' + ComputerName + ' -n 1');

        StrOutput: = objExec.StdOut.ReadAll;

        RegEx: = HISUtils.RegExpr;

        RegEx.Expression: = '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})';


        Regex.Exec(StrOutput);

        if RegEx.MatchPos[0] then

            result: = RegEx.Substitute('$&')

        else

            result: = 'IP Address colud not be resolved.!';

                  

               

    end;

  • jackson_1's avatar
    jackson_1
    Frequent Contributor
     

    there is a change in windows 7 OS.



    function ResolveIP(ComputerName): string;

     


    var

        objShell,objExec,RegEx;

    var

        StrOutput: string;

       

    begin


        objShell: = Sys.OleObject['WScript.Shell'];

        objExec: = objShell.Exec('Ping ' + ComputerName + ' -4');

        StrOutput: = objExec.StdOut.ReadAll;

        RegEx: = HISUtils.RegExpr;

        RegEx.Expression: = '(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})';


        Regex.Exec(StrOutput);

        if RegEx.MatchPos[0] then

            result: = RegEx.Substitute('$&')

        else

            result: = 'IP Address colud not be resolved.!';

                  

               

    end;