Netdocu

Netdocu

Postby Otto » Sat Mar 09, 2013 7:28 pm

Hello,
I made a little program for network documentation.
With a CMD program I search for all IP addresses in a given IP range (PING) the result is redirected into a file.
Netdocu reads the information into a dbf file.
I added some more fields:
For e.g.
device type, friendly name, location, USERNAME, PASSWORD, UPDATETIME, Notes

All the fields are shown with xBrowse and you can edit with xbrowse build in inline editing.
Thanks to Mr. Rao en-/decryption is working fine now. So your data is save.

This is a work in progress and I will add new functions. Maybe this is useful for someone else too.
Please change function add-function and the bat-file because PING in my case returns the results in German.

Best regards,
Otto

http://www.atzwanger-software.com/fw/netdocu.zip

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Netdocu

Postby Otto » Sun Mar 10, 2013 6:49 pm

Hello,
now printing is ready too.
Best regards,
Otto

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Netdocu

Postby Silvio.Falconi » Mon Mar 11, 2013 8:18 am

Otto,
I tried on my school .
We have many Pcs linked ( over 250) as you can see here

Image










With your sample showed any record !!!
Perhaps is there an error or It need a specific net ?

logIp.txt and logname.txt are empty !!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Netdocu

Postby ADutheil » Mon Mar 11, 2013 11:39 am

Silvio,

did you edit the file get_all_ip.bat to fit your network IP range and change find "wort" to find "whatever_is_wort_in_italian" ?
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Netdocu

Postby Silvio.Falconi » Mon Mar 11, 2013 7:21 pm

Yes of course, I change also the IP

My school have the IP 172.168.15.XXX

for the Wort I not Understood HOw ans Insert the name Pc

Code: Select all  Expand view  RUN
for /l %%i in (1,1,254) do @ping 172.168.15.%%i -n 1 -w 100 | find "Pc" >>logIP.txt


or How I can search them ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Netdocu

Postby Silvio.Falconi » Mon Mar 11, 2013 7:36 pm

Why not use a function on xharbour to get all IP ?

I found this for Java
but I not Know how converte it on xharbour

Code: Select all  Expand view  RUN

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
import java.io.*;
import java.awt.image.*;
import java.net.*;




public class NetScanner implements Runnable
{
    String str;
    int nub;

    public NetScanner(String str,int nub)
    {
        this.str = str;
        this.nub = nub;
    }
/*  
    public void checkHost()
    {
        for(int i=0; i<256;i++)
        {
            if(IntelAddress.getByName(str+"."+i).isReachable(1000))
                System.out.println("host"+str+"."+i+"is connected");
        }

    }
*/

    public void run ()
    {
        try
        {
        for(int i=nub; i<nub+10;i++)
        {

        System.out.println(".......");
        System.out.println(str);
        System.out.println(nub);
            if(InetAddress.getByName(str+"."+i).isReachable(1000))
                System.out.println("host"+str+"."+i+"is connected");
        }
        }
        catch(Exception e){System.out.println(e);}
    }
    public static void main(String []args)
    {
        //System.out.println("give subnet");
        //Scanner out = new Scanner(System.in);
        //NetScanner n = new NetScanner(out.next());
        Thread t[] = new Thread[25];
        for(int i=0; i<25;i++)
        {
            t[i] = new Thread(new NetScanner("10.124.168",i*10));
        }
        for(int i=0; i<25;i++)
        {
            t[i].start();
        }

    }

}






this on VbNet


Code: Select all  Expand view  RUN


Public Shared Function GetAllIP(Optional ByVal args As String() = Nothing) As Integer
   'args in the signature is optional, without it
   '
the function will simply get the hostname
   'of the local machine then go from there
   Dim strHostName As New String("")
   If args.Length = 0 Then
   '
Getting Ip address of local machine...
   ' First get the host name of local machine.
    strHostName = DNS.GetHostName()
       Console.WriteLine("Local Machine'
s Host Name: " + strHostName)
    Else
       strHostName = args(0)
    End If

    ' Then using host name, get the IP address list..
    Dim ipEntry As IPHostEntry = DNS.GetHostByName(strHostName)
    Dim addr As IPAddress() = ipEntry.AddressList

    Dim i As Integer = 0
    While i < addr.Length
       Console.WriteLine("
IP Address {0}: {1} ", i, addr(i).ToString())
       System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
    End While
    Return 0
End Function
















Visual C#.NET
Get all IP Address, MacAddress in a LAN without using Ping() Function like arp -a(quick output)

Code: Select all  Expand view  RUN
Get all IP Address, MacAddress in a LAN without using Ping() Function like arp -a(quick output)
using System.Runtime.InteropServices;
using System.Net;
using System.Net.NetworkInformation;

// Get my PC IP address
Console.WriteLine("My IP : {0}", GetIPAddress());
// Get My PC MAC address
Console.WriteLine("My MAC: {0}", GetMacAddress());
// Get all devices on network
Dictionary<IPAddress, PhysicalAddress> all = GetAllDevicesOnLAN();
foreach (KeyValuePair<IPAddress, PhysicalAddress> kvp in all)
{
    Console.WriteLine("IP : {0}\n MAC {1}", kvp.Key, kvp.Value);
}
 
/// <summary>
/// MIB_IPNETROW structure returned by GetIpNetTable
/// DO NOT MODIFY THIS STRUCTURE.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
struct MIB_IPNETROW
{
    [MarshalAs(UnmanagedType.U4)]
    public int dwIndex;
    [MarshalAs(UnmanagedType.U4)]
    public int dwPhysAddrLen;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac0;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac1;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac2;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac3;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac4;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac5;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac6;
    [MarshalAs(UnmanagedType.U1)]
    public byte mac7;
    [MarshalAs(UnmanagedType.U4)]
    public int dwAddr;
    [MarshalAs(UnmanagedType.U4)]
    public int dwType;
}

/// <summary>
/// GetIpNetTable external method
/// </summary>
/// <param name="pIpNetTable"></param>
/// <param name="pdwSize"></param>
/// <param name="bOrder"></param>
/// <returns></returns>
[DllImport("IpHlpApi.dll")]
[return: MarshalAs(UnmanagedType.U4)]
static extern int GetIpNetTable(IntPtr pIpNetTable,
      [MarshalAs(UnmanagedType.U4)] ref int pdwSize, bool bOrder);

/// <summary>
/// Error codes GetIpNetTable returns that we recognise
/// </summary>
const int ERROR_INSUFFICIENT_BUFFER = 122;
/// <summary>
/// Get the IP and MAC addresses of all known devices on the LAN
/// </summary>
/// <remarks>
/// 1) This table is not updated often - it can take some human-scale time
///    to notice that a device has dropped off the network, or a new device
///    has connected.
/// 2) This discards non-local devices if they are found - these are multicast
///    and can be discarded by IP address range.
/// </remarks>
/// <returns></returns>
private static Dictionary<IPAddress, PhysicalAddress> GetAllDevicesOnLAN()
{
    Dictionary<IPAddress, PhysicalAddress> all = new Dictionary<IPAddress, PhysicalAddress>();
    // Add this PC to the list...
    all.Add(GetIPAddress(), GetMacAddress());
    int spaceForNetTable = 0;
    // Get the space needed
    // We do that by requesting the table, but not giving any space at all.
    // The return value will tell us how much we actually need.
    GetIpNetTable(IntPtr.Zero, ref spaceForNetTable, false);
    // Allocate the space
    // We use a try-finally block to ensure release.
    IntPtr rawTable = IntPtr.Zero;
    try
    {
        rawTable = Marshal.AllocCoTaskMem(spaceForNetTable);
        // Get the actual data
        int errorCode = GetIpNetTable(rawTable, ref spaceForNetTable, false);
        if (errorCode != 0)
        {
            // Failed for some reason - can do no more here.
            throw new Exception(string.Format(
              "Unable to retrieve network table. Error code {0}", errorCode));
        }
        // Get the rows count
        int rowsCount = Marshal.ReadInt32(rawTable);
        IntPtr currentBuffer = new IntPtr(rawTable.ToInt64() + Marshal.SizeOf(typeof(Int32)));
        // Convert the raw table to individual entries
        MIB_IPNETROW[] rows = new MIB_IPNETROW[rowsCount];
        for (int index = 0; index < rowsCount; index++)
        {
            rows[index] = (MIB_IPNETROW)Marshal.PtrToStructure(new IntPtr(currentBuffer.ToInt64() +
                                        (index * Marshal.SizeOf(typeof(MIB_IPNETROW)))
                                       ),
                                        typeof(MIB_IPNETROW));
        }
        // Define the dummy entries list (we can discard these)
        PhysicalAddress virtualMAC = new PhysicalAddress(new byte[] { 0, 0, 0, 0, 0, 0 });
        PhysicalAddress broadcastMAC = new PhysicalAddress(new byte[] { 255, 255, 255, 255, 255, 255 });
        foreach (MIB_IPNETROW row in rows)
        {
            IPAddress ip = new IPAddress(BitConverter.GetBytes(row.dwAddr));
            byte[] rawMAC = new byte[] { row.mac0, row.mac1, row.mac2, row.mac3, row.mac4, row.mac5 };
            PhysicalAddress pa = new PhysicalAddress(rawMAC);
            if (!pa.Equals(virtualMAC) && !pa.Equals(broadcastMAC) && !IsMulticast(ip))
            {
                //Console.WriteLine("IP: {0}\t\tMAC: {1}", ip.ToString(), pa.ToString());
                if (!all.ContainsKey(ip))
                {
                    all.Add(ip, pa);
                }
            }
        }
    }
    finally
    {
        // Release the memory.
        Marshal.FreeCoTaskMem(rawTable);
    }
    return all;
}

/// <summary>
/// Gets the IP address of the current PC
/// </summary>
/// <returns></returns>
private static IPAddress GetIPAddress()
{
    String strHostName = Dns.GetHostName();
    IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
    IPAddress[] addr = ipEntry.AddressList;
    foreach (IPAddress ip in addr)
    {
        if (!ip.IsIPv6LinkLocal)
        {
            return (ip);
        }
    }
    return addr.Length > 0 ? addr[0] : null;
}

/// <summary>
/// Gets the MAC address of the current PC.
/// </summary>
/// <returns></returns>
private static PhysicalAddress GetMacAddress()
{
    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
    {
        // Only consider Ethernet network interfaces
        if (nic.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
            nic.OperationalStatus == OperationalStatus.Up)
        {
            return nic.GetPhysicalAddress();
        }
    }
    return null;
}

/// <summary>
/// Returns true if the specified IP address is a multicast address
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
private static bool IsMulticast(IPAddress ip)
{
    bool result = true;
    if (!ip.IsIPv6Multicast)
    {
        byte highIP = ip.GetAddressBytes()[0];
        if (highIP < 224 || highIP > 239)
        {
            result = false;
        }
    }
    return result;
}
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Netdocu

Postby ADutheil » Mon Mar 11, 2013 8:10 pm

Silvio,

I understood now. Wort is the end of the word Antwort that means response in german. Só you shoul try this way:

Code: Select all  Expand view  RUN
for /l %%i in (1,1,254) do @ping 172.168.15.%%i -n 1 -w 100 | find "Risposta" >>logIP.txt


Here with portuguese Windows and using find "resposta" I get all the IPs connected in my lan.
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Netdocu

Postby Gale FORd » Mon Mar 11, 2013 8:39 pm

Ping is not always available. It requires ICMP Echo function to be operational. Some devices and networks block this feature.

We have security cameras and other devices at different locations in the southwest that ping will not work with. So I setup a routine to use the socket function on port 80 (http) to test each ip address. If it cannot make a simple socket connection within a maximum of 10 tries, then it emails an error message to support group.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Netdocu

Postby Otto » Mon Mar 11, 2013 10:26 pm

Thank you Gale.
The aim of this little program is to document the infrastructure for our service technics. The ping script makes it easier for the first time to add all ping able devices to the dbf file in other words to make an inventory.
As we use en-/decrypt the files can remain on the customers PC.
Now if you have to support you can look up all the necessary information. We also have a memo field where you can add extra information.
Maybe you can share your function too so we can add it.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: Netdocu

Postby Silvio.Falconi » Tue Mar 12, 2013 11:17 am

Thanks Otto,
Thanks ADutheil


Now run ok only I have a small error on :


Image

on txt file I have each line with

Risposta da 172.15.20.9: byte=32 durata=97ms TTL=64

it erase the "d" any solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Netdocu

Postby Silvio.Falconi » Tue Mar 12, 2013 11:25 am

resolved !
oBrw:time:bEditValue := { |x| substr(FIELD->time,10) }
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7063
Joined: Thu Oct 18, 2012 7:17 pm

Re: Netdocu

Postby Gale FORd » Tue Mar 12, 2013 3:39 pm

Here is a little test file that I expanded into the automated test program.
If you want to try it by entering 1 ip address at a time use
testip.exe /dialog

I commented the email section out because I use an ActiveX smtp program.

Code: Select all  Expand view  RUN

#include "fivewin.ch"
#DEFINE    RDD_SYS             "DBFCDX"
#DEFINE    RDD_ACCT            "DBFCDX"
REQUEST DBFCDX
#define nWaitTime       1000

static oWnd, oSocket, oTimer, nTry, nTries, cIPAddress, lConnectOK, lGoOn
static lDialog, lSendEmail, lStatusUpdate, lEmailToMe
static cFileName
static lDebug

function main( cParam1, cParam2, cParam3, cParam4 )
   local oDlg
   local cAddress := '                                    '
   local nCounter
   local cPath
   local aResults
   local oMail, cSubject, cMsg
   local lUseHtml
   local cParams
   local aDir

   lSendEmail := .f.
   lUseHtml := .t.
   lDebug := upper( getenv("clipdebug") ) = 'ON'
   if lDebug
      ALTD(1)
      wait
   else
      ALTD(0)
   endif
   set epoch to year(date())-50

   rddsetdefault( RDD_SYS )
   if cParam1 == nil
      cParam1 := ''
   endif
   if cParam2 == nil
      cParam2 := ''
   endif
   if cParam3 == nil
      cParam3 := ''
   endif
   if cParam4 == nil
      cParam4 := ''
   endif
   cParams := upper(cParam1+cParam2+cParam3+cParam4)
   lDialog := .f.

   cFileName := 'testip'

   if '/DIALOG' $ cParams
      lDialog := .t.
   endif
   if '/FORCEEMAIL' $ cParams
       lSendEmail := .t.
   else
      lSendEmail := .f.
   endif
   if '/STATUS' $ cParams
      lStatusUpdate := .t.
   else
      lStatusUpdate := .f.
   endif
   if '/TOME' $ cParams
      lEmailToMe := .t.
   else
      lEmailToMe := .f.
   endif
   nTries := 10           // # tries to connect before giving up

   lGoOn := .t.

   DEFINE WINDOW oWnd TITLE "Test IP socket" from 2, 2 to 25, 70

   // DEFINE BUTTONBAR oBar OF oWnd _3D

   //DEFINE BUTTON OF oBar ACTION Client() TOOLTIP "Connect"
   if lDialog
      @ 1.2, 2 SAY "IP Address:" OF oWnd
      @ 1.4, 10 GET cAddress OF oWnd PICTURE "@!K" SIZE 200, 20
      @ 4, 2 BUTTON "&Ok"  OF oWnd SIZE 50,20 default        ;
         ACTION  Test1Ip( cAddress )
      @ 4, 15 BUTTON "&Cancel" OF oWnd SIZE 50, 20 ACTION (lGoOn := .f., oWnd:end())
   else
      @ 1.2, 2 SAY "Running preset tests" OF oWnd
      @ 4, 15 BUTTON "&Cancel" OF oWnd SIZE 50, 20 ACTION (lGoOn := .f.)
   endif

   if lDialog
      ACTIVATE WINDOW oWnd
   else
      ACTIVATE WINDOW oWnd on init TestAllIp()
   endif
return nil

function TestAllIp()
   if .not. file( cFileName+'.dbf' )
      CreateIpFile( cFileName )
   endif
   use ( cFileName ) share
   if flock()
      do while .not. eof()
         if rlock()
            replace ltestdate with date()
            replace ltesttime with time()
            if Test1IP( trim( IPAddr ) )
               replace ltestresu with 'Passed'
            else
               replace ltestresu with 'Failed'
            endif
            if ( ltestresu = 'Failed' .or. lSendEmail ) .and. !lStatusUpdate
               msginfo( 'IP quick check: '+trim(ltestresu)+' for '+trim(ipname)+' IP: '+trim( IPAddr) )
               // If you setup the email then uncomment below
               // sendemail()
            endif
         endif
         //tracelog( trim( IPAddr), trim(IPName), ltestresu, ltestdate, ltesttime )
         if !lGoOn
            go bottom
         endif
         skip
      enddo
      dbunlock()
      if lGoOn .and. lStatusUpdate
         go top
         xbrowse()
         // If you setup the email then uncomment below
         // sendemail( lStatusUpdate )
      endif
   else
      msginfo( 'Cannot lock '+cFileName )
      // If you setup the email then uncomment below
      // senderror( 'Cannot lock '+cFileName)
   endif
   oWnd:end()
return nil

function test1IP( cAddress )
   local lGoOn := .t.
   local nCounter
   local cPath
   local aResults
   local lSendEmail
   local oMail, cSubject, cMsg
   local lUseHtml
   local aDir

   if oSocket != NIL
      oSocket:End()
   endif
   if oTimer != NIL
      oTimer:End()
   endif

   if val( cAddress ) = 0
      cIPAddress := gethostbyname( cAddress )
   else
      cIPAddress := trim( cAddress )
   endif
   //tracelog( val( cAddress ), cAddress, cIPAddress )

   lConnectOK := .f.
   nTry := 1

   oSocket = TSocket():New( 80 )
   oSocket:lDebug := .t.
   oSocket:cLogFile := 'test.log'
   //oSocket:bRead    = { | oSocket | MsgInfo( oSocket:GetData() ) }

   // Never use a MsgInfo() here because it hangs Windows!!!
   oSocket:bConnect = { || lConnectOK := .T. }

   oSocket:bClose   = { || if( lDialog, MsgInfo( "Server has closed!" ), .t. ) }

   // oSocket:Connect( cIPAddress ) // use the server IP address here
   Timer_Connect()

   Define Timer oTimer Interval nWaitTime Action Timer_Connect() OF oWnd
   Activate Timer oTimer
   Do While nTry <= nTries .and. !lConnectOK .and. lGoOn
      SysWait(1)
      SysRefresh()
      Loop
   Enddo
   oTimer:End()
   oSocket:End()
   if lConnectOK
      oWnd:SetText( "Address "+cIPAddress+" OK" )
      if lDialog
         MsgInfo("Connection ESTABLISHED")
      endif
   else
      oWnd:SetText( "Socket Closed" )
      if lDialog
         MsgInfo("Connection can NOT be ESTABLISHED")
      endif
   endif
   /*
   if lConnectOK
      oWnd:SetText( 'Test ok for '+cIPAddress )
      msginfo( 'Test ok for '+cIPAddress )
   else
      oWnd:SetText( 'Test failed for '+cIPAddress )
      msginfo( 'Test failed for '+cIPAddress )
   endif
   */

return( lConnectOK )

function Timer_Connect()
   IF nTry <= nTries .and. !lConnectOK
      if nTry > 1
         oWnd:SetText("Connection Try : "+ALLTRIM(STR(nTry)))
      endif
      oSocket:Connect( cIPAddress )
      nTry++
   endif
return nil


function senderror( cMessage )
   local oMail, cSubject, cMsg
   local cTo
   local lWasFailure

   cSubject := 'Error during IP quick check: '+cMessage

   // The following code only works with OSSMTP email component
   oMail := CreateObject("OSSMTP.SMTPSession")
   oMail:Server := "smtp.mydomain.com"
   oMail:MailFrom := "myuser@mydomain.com"
   oMail:RaiseError := .f.
   oMail:AuthenticationType := 2
   oMail:Password := 'mypassword'
   oMail:POPServer := 'pop.mydomain.com'
   oMail:Username := 'myuser@mydomain.com'

   if lSendStatus == nil
      lSendStatus := .f.
   endif
   lWasFailure := .f.

   cMsg := [<html>]+CRLF
   cMsg += [<head>]+CRLF
   cMsg += [<meta http-equiv = "Content-Language" content = "en-us">]+CRLF
   cMsg += [<meta http-equiv = "Content-Type" content = "text/html; charset=windows-1252">]+CRLF
   cMsg += [<title>IP test notification]+[</title>]+CRLF
   cMsg += [</head>]+CRLF
   cMsg += [<body>]+CRLF
   cMsg += [Error occurred when running the IP quick check program<br>&nbsp;]+CRLF
   cMsg += [The test could not complete so the status of the IP address is unknown at this time<br>&nbsp;]+CRLF
   cMsg += [<br>&nbsp;</body>]+CRLF
   cMsg += [</html>]

   oMail:MessageSubject := cSubject
   oMail:MessageHTML := cMsg
   if lDebug .or. lEmailToMe
      cTo := gete("USERNAME")+"@mydomain.com"
   else
      cTo := "Security.Notice@mydomain.com"
      if !lSendStatus .and. .not. empty( emailerr )
         cTo += ','+trim( emailerr )
      endif
   endif
   oMail:SendTo := cTo
   oMail:SendEmail()
return nil

function sendemail( lSendStatus )
   local oMail, cSubject, cMsg
   local cTo
   local lWasFailure

   if lSendStatus == nil
      lSendStatus := .f.
   endif
   lWasFailure := .f.

   if lSendStatus
      go top
      do while .not. eof()
         if ltestresu = 'Failed'
            lWasFailure := .t.
            exit
         endif
         skip
      enddo
      cSubject := 'IP Staus Update'
      if lWasFailure
         cSubject += ' -- Failure(s) found!!'
      endif
   else
      cSubject := 'IP quick check: '+trim(ltestresu)+' for '+trim(ipname)+' IP: '+trim( IPAddr)
   endif

   // The following code only works with OSSMTP email component
   oMail := CreateObject("OSSMTP.SMTPSession")
   oMail:Server := "smtp.mydomain.com"
   oMail:MailFrom := "myuser@mydomain.com"
   oMail:RaiseError := .f.
   oMail:AuthenticationType := 2
   oMail:Password := 'mypassword'
   oMail:POPServer := 'pop.mydomain.com'
   oMail:Username := 'myuser@mydomain.com'

   cMsg := [<html>]+CRLF
   cMsg += [<head>]+CRLF
   cMsg += [<meta http-equiv = "Content-Language" content = "en-us">]+CRLF
   cMsg += [<meta http-equiv = "Content-Type" content = "text/html; charset=windows-1252">]+CRLF
   cMsg += [<title>IP test notification]+[</title>]+CRLF
   cMsg += [</head>]+CRLF
   cMsg += [<body>]+CRLF
   if lSendStatus
      cMsg += [<table border="1" width="600" id="table1">]+CRLF
      cMsg += [<tr>]+CRLF
      cMsg += [  <td align="center" width="50">Name</td>]+CRLF
      cMsg += [  <td align="center" width="50">IP Address</td>]+CRLF
      cMsg += [  <td align="center" width="40">Status</td>]+CRLF
      cMsg += [  <td align="center" width="50">CheckDate</td>]+CRLF
      cMsg += [  <td align="center" width="50">Time</td>]+CRLF
      cMsg += [</tr>]+CRLF
      go top
      do while .not. eof()
         cMsg += [<tr>]+CRLF
         cMsg += HTMLRecord( trim(ipname) )
         cMsg += HTMLRecord( trim(ipaddr) )
         cMsg += HTMLRecord( trim(ltestresu) )
         cMsg += HTMLRecord( dtoc(ltestdate), 'Center' )
         cMsg += HTMLRecord( ltesttime, 'Center' )
         cMsg += [</tr>]+CRLF
         skip
      enddo
      cMsg += [</table>]+CRLF
   else
      cMsg += [Test of IP Address: ]+trim(ltestresu)+[<br>]+CRLF
      cMsg += [When: ]+dtoc( ltestdate )+' at '+ltesttime+[<br>]+CRLF
      cMsg += [Where: ]+trim( ipname )+[<br>]+CRLF
      cMsg += [IP Address: ]+trim( IPAddr )+[<br>]+CRLF
   endif
   cMsg += [<br>&nbsp;</body>]+CRLF
   cMsg += [</html>]

   oMail:MessageSubject := cSubject
   oMail:MessageHTML := cMsg
   if lDebug .or. lEmailToMe
      cTo := gete("USERNAME")+"@mydomain.com"
   else
      cTo := "Security.Notice@mydomain.com"
      if !lSendStatus .and. .not. empty( emailerr )
         cTo += ','+trim( emailerr )
      endif
   endif
   oMail:SendTo := cTo
   oMail:SendEmail()
return nil

function HTMLRecord( cData, cAlign )
   local cText
   if cAlign == nil
      cAlign := 'Left'
   endif
   cText := [  <td align="]+cAlign+["]
   if ltestresu = 'Failed'
      cText += [ bgcolor="#FF0000"><b>]
   else
      cText += [>]
   endif
   cText += cData
   if ltestresu = 'Failed'
      cText += [</b>]
   endif
   cText += [</td>]+CRLF
return cText

function CreateIpFile( cFile )
   local aDbf, aHosts, cSub1, cSub2
   aDbf := {}
   aadd( aDbf, { "IPADDR",  "C", 20, 0 } ) // IP address or name like
   aadd( aDbf, { "IPNAME",  "C", 25, 0 } ) // Name of Addressame like
   aadd( aDbf, { "LTESTDATE","D", 8, 0 } )  // Last Test Date
   aadd( aDbf, { "LTESTTIME","C", 8, 0 } )  // Last Test Time
   aadd( aDbf, { "LTESTRESU", "C", 20, 0 } ) // Last Test Reslult
   aadd( aDbf, { "EMAILERR", "C", 200, 0 } ) // Email errors to seperated by comma's
   dbcreate( cFile, aDbf )

   // Add 3 records for starters
   // Current IP address and 1 on each side

   INETINIT()
   aHosts = INETGETHOSTS( NETNAME() )
   INETCLEANUP()
   cSub1 := substr( aHosts[ 1 ], 1, rat('.',aHosts[ 1 ]) )
   cSub2 := substr( aHosts[ 1 ], rat('.',aHosts[ 1 ])+1 )

   use ( cFileName ) share
   append blank
   replace ipaddr with aHosts[ 1 ]
   replace ipname with NETNAME()
   append blank
   replace ipaddr with cSub1+alltrim(str(val(cSub2)-1))
   replace ipname with NETNAME()+' -1'     //GetHostByAddress(trim(ipaddr))
   append blank
   replace ipaddr with cSub1+alltrim(str(val(cSub2)+1))
   replace ipname with NETNAME()+' +1'     //GetHostByAddress(trim(ipaddr))
   use
return nil
 
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 15 guests