Link to home
Start Free TrialLog in
Avatar of attila01
attila01

asked on

How to display the client's IP Address?

Is it possible to create a button on a form on which the user can click and then his PC's IP Address will be displayed?
I guess the button script should perform a ping request and the Dos window should be saved in a doc file. Or can the script take the IP Address directly from the PC's setting?
Could you give me the script for the button?
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Try something with Shell() and the program IPCONFIG.

But why do you want to know? This has got very little to do with Notes/Domino, I think. Furthermore, if you have DHCP installed and your PC obtains its IP-address from the DHCP-server, the address could change every day.
Avatar of attila01
attila01

ASKER

The Form will be in a Helpdesk database. When a user sends a request to the helpdesk team the user should fill in his/her PC'c IP Address as well.
You're right the IP Address changes in every 14 or 28 days or so but it's unlikely that the IP Address changes the day when somebody from the helpdesk team wants to connect remotely to the client. It isn't impossible, although.

Is this impossible to create a button, click on it and an IPCONFIG command will be send?
And what about creating a field for the IP Address on the form? I mean 4 times 3 digits where the user can make no mistake.
I use this on a button that I send to users you could easily adapt:

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim uidoc As NotesUIDocument
      Dim db As NotesDatabase
      Dim tempCN As String
      Dim tempUN As String
      Dim tempServer As String
      Dim tempMessage As String
      Dim s As New NotesSession
      Dim maildoc As NotesDocument
      Set db = session.CurrentDatabase
      Set maildoc = New NotesDocument(db)
      maildoc.form = "memo"
      
      tempCN$ = Environ("Computername")
      tempUN$ = Environ("Username")
      tempServer$ = Environ("LogonServer")
      tempMessage$ = "The version of Notes that you are running is :" + s.NotesVersion _
      & Chr(13) _
      & "Your Notes username is : " + s.UserName _
      & Chr(13) _
      & Chr(13) _
      & "Your hostname  is : " + tempCN$ _
      & Chr (13) _
      &  "You are logged in to NT as : " + tempUN$ _
      & Chr(13) _
      & "You are attached to NT Server : " + tempServer$
      
      Messagebox  tempMessage$, 0+64, "Session Information for " + tempCN$
      
      
      maildoc.SendTo = "Support Centre"
      maildoc.Subject = "Results of hostname"
      
      Set rtbody = New NotesRichTextItem( maildoc, "Body" )
      
      Call rtbody.AppendText("Hostname is " + tempCN$)
      
      Call Maildoc.send(False)
      
End Sub
It works fine but this message window shouldn't be send by mail.

This message window should be send along with the request form. As an attachment but I don't know how.
If the script can display username it can do that with the IP Address, too I hope.
I will try it tomorrow.

But it would be very helpful for me if you could told me how to embed the message into the request form.
ASKER CERTIFIED SOLUTION
Avatar of mbonaci
mbonaci
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here how I would do that:

Create a Button with this @Formula:
FIELD LocalAddress:=LocalAddress;
@Command([ToolsRunMacro]; "getLocalAddress");
@SetField("LocalAddress";@Environment("LocalAddress"))


Create a Field with this name: LocalAddress

Create an Agent with Schedule options set to: Never
The Agent name should be: getLocalAddress
The Agent source is this:

import lotus.domino.*;
import java.net.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

            try {
                  Session session = NotesFactory.createSession();
                  java.net.InetAddress i = java.net.InetAddress.getLocalHost();
                  session.setEnvironmentVar("LocalAddress",i.getHostAddress(), false);
            } catch(Exception e) {
                  e.printStackTrace();
            }
      }
}



That should do it.


Small note, the Request Form with the Button and the Field "LocalAddress", and the Agent "getLocalAddress" has to be located in same Database.
After Field value being set can the Request Form be sent anywere because the Agent is no more used.



I have tried various methods over the years to get the IP address reliably.

mbonaci methods did not work for me in all version of windows.
I ended up using ipconfig in a batch file that creates a single line text file with the IP address. I tne read the text file.
Works in all Windows version.
I will have to try Zvonko's method as it looks good on paper.

just my $0.02

I hope this helps !
on paper? it is tested and working!
Hi All,

First the script from mbonaci:
I know "Public" from Java and "Dim" from Lotus script.
But I think I should select JavaScript when editing the button. If I paste the code and save it I get the error message: - missing ; before statement - and the very first line shows the error.
My Agent source is JAVA.

On the other hand the script from Zvonko:
It's Java definitely.
I created the button with the Formula and I created a Field LocalAddress.
When I create the Agent in the same database I could select Simple Action, Lotus Script. Imported Java, and JavaScript.
I can select the first 3 without any problem but the moment I select JavaScript I get the error NSD Running.

With my Lotus Notes is everything ok I only get NSD Running when I want to create an Agent with JavaScript.

I was happy to get 3 solution to my question but now I only can use the first from sg405222 which works fine but the result can't be embedded to the Form.

In the Control Panel I can see 2 Java installed:
Java Plug-in 1.4.2_01
Java Plug-in 1.4.0

When you get your solution running, then it is all fine.
And we do not need to search the option where to set an Agent to be JavaScript.
Are you using Designer version R8 or R9? ;-)
I'm using Designer version R 6.5
In that version it is NOT possible to have JavaScript Agents.
There is NO version with an option to have Agents written in JavaScript.
Therefore I asked for not released versions (as a joke :)
I got it now :-)

But you wrote that your Agent source is JAVA although there is no version able to use JAVA as Agent source.

That is a pretty mess! :-(

Then what can I do?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've all the rights to the databases, I've manager access. with all the options like  Create Lotus script/Java Agent.
Enable Java applets. Enable JavaScript etc.

I checked other databases as well where I have all rights but I get always and in every database an NSD Running error when I want to create a Java agent.
I didn't get the basic Java source skeleton for the Java Agent.

Should I update my Java Plug-in?

No, you should not.
The Java Virtual Mashine is installed together with the Notes client and Designer installation. You need no extra Java install. Even worse, you additional Java JDKs do disturb the Notes JDK 1.4.1
My colleaques checked and everybody could make a Java agent in their mail database.

This is something with my PC's setting. I will make this Agent at home or at another PC.
But it's strange.
On a different note all together I'm a  admin not prorgrammer so don't go near Java and only just started to dabble with Lotus script but this works>

Create a field called host

Create a hotspot button with the following formula (adapted from original)

Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim uidoc As NotesUIDocument
      Dim tempCN As String
      Dim tempUN As String
      Dim tempServer As String
      Dim tempMessage As String
      Dim Host As String
      
      Set uidoc = workspace.CurrentDocument
      
      tempCN$ = Environ("Computername")
      tempUN$ = Environ("Username")
      tempServer$ = Environ("LogonServer")
      tempMessage$ =  "Your hostname  is : " + tempCN$
      
      Messagebox  tempMessage$, 0+64, "Session Information for " + tempCN$
      
      Call uidoc.FieldSetText("Host",tempCN$)
      
End Sub

that will populate the host field with the workstation hostname from that its a simple matter of getting the IP address (if you need it) as most systems will resolve the hostname ok

Hope that helps

Steve
forgot to take out the messagebox that I had in for testing :-)
That's exactly what I need but with the IP Address and not host name.
Take a look at to quote

"This code was found on a Visual Basic web site and converted to LotusScript. It is a LotusScript class that allows you to convert a host name to its IP address. To use, create a new HostName object. Then check the IPAddress property of the new object to get the IP address. The property is a string. "

http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&87256B280015193F87256CA300788B6E
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yea, it works really great!
Nice job Steve :-)
I tried Zvonko's solution on my home PC and it works and he says sg405222's solution works as well.
Unfortunately, I get "NSD Running" error as soon as I click on a button with Java agent or when I want to create Lotus script with the option "Uselsx *javacon".

I've already deleted additional Java plug-in, Java web start etc.
Do I have other choice then reinstall my company's PC? (full reinstall)

SysExpert said that mbonaci's methods did not work in all version of windows. I paste his whole script as lotus script and I get the error "Unexpected As; Expected ="

But thanks for the solutions.

My recommendation: full reinstall (remove or rename Notes directories and do a new install)
Sorry,the Accepted answer should have been Zvonko's solution.
No problem at all.

See you.