Page 2 of 3 <123>
Topic Options
#72930 - 2003-02-07 03:13 PM Re: FindMe KiXform
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
almost more trouble than it is worth... even for basic stuff

code:
Function MidStr($string,$leftchar,$rightchar,optional $trim)
if not instr($string,$leftchar) or not instr($string,$rightchar)
exit 1
return
endif
$MidStr = split(split($string,$leftchar)[1],$rightchar)[0]
if $trim
$MidStr=Trim($MidStr)
endif
endif

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#72931 - 2003-02-07 03:19 PM Re: FindMe KiXform
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
BTW...

more functions used to provide equivalent results...



break on

$w=WinsResolve('username')
$l=lookup($w)

$w
$l

Function WinsResolve($username,optional $winsserver)
    dim $winsserver$ipconfig$line$wins1$wins2$file$WINSarray$ip
    if not $winsserver
        $return=WSHPipe('%comspec% /c ipconfig /all| find "Primary WINS Server"',1)[0]
        if instr($return,"Primary WINS Server")
            $WinsServer=trim(split($return,':')[1])
            endif
        endif
    if not $winsserver    exit 1        return        endif

    $file='c:\winscl.txt'
    del $file
    $parameters="$WINSserver","QN",$username,"1","03","0","EX"
    $X = open (1"$file"5)
    for each $param in $parameters
        $X = writeline(1$param + @CRLF)
        next
    $X = Close(1)

    $WINSarray=WshPipe("%comspec% /c winscl.exe T NOME< $file",1)
    del $file
    for each $line in $WinsArray
        if instr($line,'Address is (')
            $IP = split(split($line,'(')[1],')')[0]
                  endif
        next
    if $ip
        $WinsResolve='$ip'
    else 
        exit 1
        return
        endif
    endfunction

Function Lookup($ip)
    Dim $return
    $return=WSHPipe('%comspec% /c nslookup $ip | find "Name:"',1)[0]
    if instr($return,"Name:")
        $lookup=trim(split($return,':')[1])
    else
        exit 1
        $lookup=""
        endif
    endfunction

Function WshPipe($ShellCMDOPTIONAL $NoEcho)
   Dim $WshShell$oExec$AllOutput$Exit$WshExitCode
   $WshErrorMsg=""
   $WshShell=CreateObject("WScript.Shell")
   $oExec=$WshShell.Exec($ShellCMD)
   While $Exit<>1
      Dim $Output
      Select
      Case Not $oExec.StdOut.AtEndOfStream         $Output=$oExec.StdOut.ReadAll
      Case Not $oExec.StdErr.AtEndOfStream         $Output=$oExec.StdErr.ReadAll
                           $WshErrorMsg = $Output
      Case 1                       $Output=-1
      EndSelect
      If $Output=-1
         If $oExec.Status=1
            $Exit=1
         Endif
      Else
         If $NoEcho<>1
            ? $Output
         Endif
         $AllOutput = $AllOutput + $Output
      Endif
   Loop
   $WshExitCode=$oExec.ExitCode
   $WshPipe=split($AllOutput,chr(10))
   Exit($WshExitCode)
EndFunction

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#72932 - 2003-02-07 04:25 PM Re: FindMe KiXform
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jim,
I got to thinking...
Why use DNS to resolve the DNS name which may fail when WINS also holds the NETBIOS name?

So I replaced the *Resolve the hostname* section with this:

code:
;*********Resolve the hostname**********
$HostArray = WshPipe("%comspec% /c nbtstat -a $IP",1)
$X = InStrArray("<00> UNIQUE", $HostArray)
if $X <> -1
$txtHost.text = Trim(Split($HostArray[$X],"<")[0])
else
$txtHost.text = "Not Found in WINS" ?
endif
$Host = $txtHost.text

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72933 - 2003-02-08 07:30 AM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
Les,
Ping -a does not necessarily use dns to resolve a host name. It apparently uses whatever methods are defined in the stack, the order determined by the node type. But nbtstat may get the hostname faster than relying on WINS, and it looks shorter too.

I had to actually work at work today, so have not had much chance to look at everything else posted in this topic yet. Maybe I will over the weekend.
Jim
_________________________
Jim
--------------------

Top
#72934 - 2003-02-08 05:27 PM Re: FindMe KiXform
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Jim,
I disagree with what you say. Ping looks to DNS first to resolve a name and node type has no bearing on that. Node type determines NetBIOS search order, whether to use WINS before (H) or after (M) broadcast. NBTSTAT then follows the node type and in the case of H-node, queries WINS.

Of course the DNS server can be configured to look to WINS as well.

All this is a bit of a moot point however as you don't really need to know either the DNS or NetBIOS names (they could be different) to get to the $ share as the IP address is enough.

Try \\1.2.3.4\c$
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72935 - 2003-02-08 06:13 PM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
I am confused. I am trying to figure out how this is better than using NTNAME. I have been using this for several years to find a logged on user's computer. If the user is logged on more than once, it will only find one computer. I think the solution you are working on has the same problem. If it can find all the computers, then this may be worth it. NTNAME just appears to much easier than using winscl.exe.

At the company I work at we have probably about 140,000 computers, not counting any kind of servers. We probably have about 100 domains. I don't have admin rights to all those domains. I do not have any admin rights to the wins servers. Will this cause any problems using winscl.exe? I also could not find this as a download from Microsoft's site, so I assume that you will have to buy the reskit. Not a problem for me, but something to remember.

I have not been able to test what this thread is currently working on. I am at home recovering from a hernia operation. So I may have missed a point along the way. If this was using some sort of COM method, I probably would have jumped on it. As I said at the begining, I am just trying to understand.

Well, here is some sample code. You could probably wrap this inside wshPipe udf.
code:
$ScriptDir = @CurDir
$UserID = 'Name'
$Who = fnFindUser($UserID)
? 'Error: ' + @Error
? 'Who: ' + $Who

QUIT 1

FUNCTION fnFindUser($User)
;--- This function will find what computer a person is on.
DIM $Temp, $Reply, $FindUserError
$Temp = '%temp%\' + $User + '.tmp'
DEL $Temp
SHELL '%Comspec% /C ' + $ScriptDir + '\ntname.exe ' + $User + ' > ' + $Temp
$Nul = Open (10, $Temp, 2)
$FindUserError = @Error
IF $FindUserError = 0
$fnFindUser = ReadLine (10)
ENDIF
$Nul = Close (10)
DEL $Temp
EXIT $FindUserError
ENDFUNCTION

_________________________
Kelly

Top
#72936 - 2003-02-08 10:17 PM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
krabourn,
This looks like one of those 'too good to be true' things!

Jim
_________________________
Jim
--------------------

Top
#72937 - 2003-02-09 12:14 AM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Someone in my company was sending a net send "Please, ignore this message." and then checking NBTSTAT to find a logged on user's computer. I did not like this. I did not want to send a net message and interrupt the person working to find their computer. I spent a lot of time trying to find another way. That is when I found NTNAME. I know it was originally made to keep people from logging on more than once. But, the side benifit is that I can find out where someone is logged on without bothering them.

Like I said, I am not putting this way down. I am sure that someday I will find a use for it. It just seems like a lot of extra work. While I am sure that there some situations where NTNAME will not work, I have not run into one yet.
_________________________
Kelly

Top
#72938 - 2003-02-09 07:30 AM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
I went through the WINS Administrator query phase, and when I got tired of waiting for the GUI to respond, I too spent a short time using 'net send' and nbtstat. Then I spent way too much time looking for what I thought would be out there by the dozens. "This is so basic", I thought, "someone has to have done this already." Boy do I wish I had found this forum earlier!

Jim
_________________________
Jim
--------------------

Top
#72939 - 2003-02-11 12:31 AM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
krabourn,
Have you used ntname on Win2k? It worked right off on NT4, but not on 2000.

[ 11. February 2003, 00:32: Message edited by: JimRobinson ]
_________________________
Jim
--------------------

Top
#72940 - 2003-02-11 01:48 AM Re: FindMe KiXform
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
krabourn..

Have you tried using 'net send user ""'? It still resolves name but does not send message. This is sending from XP and 2K anyways.

Top
#72941 - 2003-02-11 02:00 AM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
Shane,
I don't believe it. To think it would be that easy. I can't even remember how many different versions of 'net send something' I tried. Now I'll bet you'll tell me that also resolves the correct Citrix session too.
_________________________
Jim
--------------------

Top
#72942 - 2003-02-11 04:26 AM Re: FindMe KiXform
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
No, but it does cook coffee [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#72943 - 2003-02-11 04:28 AM Re: FindMe KiXform
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I too could not get NTNAME to work on Win2K.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#72944 - 2003-02-11 05:41 AM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
CitrixMan

If I remember correctly, that won't work when the computer recieving is NT4. I know that does not work for NT4.

LLigetfa

Sorry, I forgot one thing about NTNAME. It uses LANA 0. Now that does not exactly match on W2K and XP. When NTNAME did not work, The nic was not the first installed. And magically my memory returns... I have seen this happen in my company when they try to make an image for different platforms. Usually the image included modems or maybe pcmcia and one of those cards would be installed before the desktop or docking stations nic. That is my experience. Most of techies don't use generic images though. [Smile]

I wish someone much smarter than me would take the included source code and fix that limitation. Oh Well....
_________________________
Kelly

Top
#72945 - 2003-02-11 07:28 PM Re: FindMe KiXform
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
It actually seems to work the same way for me when sending from NT server. Try this.

code:
 
? 'Enter a username : '
Gets $User
$IPTempFile = "%Temp%\TempFile.xxx"
$NameTempFile = "%Temp%\TempFile.yyy"

If Exist ("$IPTempFile")
Del $IPTempFile
Endif
If Exist ("$NameTempFile")
Del $NameTempFile
Endif

shell '%comspec% /c nbtstat -R'
shell '%comspec% /c net send $User ""'
shell '%comspec% /c nbtstat -c > $IPTempFile'

$filehandle = Freefilehandle()
If Open ($filehandle, $IPTempFile) = 0
$line = ReadLine ($filehandle)
While @Error = 0
$type = Trim (SubStr ($line, InStr ($line, ">")+1))
If InStr ($type, "unique")
$IPSTRING = Trim (SubStr ($type, InStr ($type, " ")+1))
$IPSTRING = SubStr ($IPSTRING, 1, InStr ($IPSTRING, " ")-1)
? $IPSTRING
Endif
$line = ReadLine ($filehandle)
Loop
Endif
$null = Close ($filehandle)

If $IPSTRING
shell '%comspec% /c ping -a $IPSTRING > $NameTempFile'
$filehandle = Freefilehandle()
If Open ($filehandle, $NameTempFile) = 0
$line = ReadLine ($filehandle)
While @Error = 0
$type = SubStr ($line, 1, 7)
If $type = "Pinging"
$NAMESTRING = SubStr ($line, InStr ($line, " ")+1)
$NAMESTRING = SubStr ($NAMESTRING, 1, InStr ($NAMESTRING, " ")-1)
? $NAMESTRING
Endif
$line = ReadLine ($filehandle)
Loop
Endif
$null = Close ($filehandle)
Endif

If Exist ("$IPTempFile")
Del $IPTempFile
Endif
If Exist ("$NameTempFile")
Del $NameTempFile
Endif

? 'DONE'
get $

"EDIT" - Changed code to search for > instead of a certain amount of chars.

[ 11. February 2003, 20:01: Message edited by: CitrixMan ]

Top
#72946 - 2003-02-12 04:33 AM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
CitrixMan

When I get back to work next week, I will test it.

Thanks
_________________________
Kelly

Top
#72947 - 2003-02-14 09:01 PM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
Net send user "" will cause a Messenger popup when the receiving host is NT4. It doesn't appear to matter what the sending host OS is (NT+ of course).

For most of this year, that's too bad for me, 'cause I still have quite a few NT boxes lying around.

Oh well, winscl still works.
_________________________
Jim
--------------------

Top
#72948 - 2003-02-14 09:29 PM Re: FindMe KiXform
JimRobinson Offline
Fresh Scripter

Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
Net send user "" will cause a Messenger popup when the receiving host is NT4. It doesn't appear to matter what the sending host OS is (NT+ of course).

For most of this year, that's too bad for me, 'cause I still have quite a few NT boxes lying around.

Oh well, winscl still works.
_________________________
Jim
--------------------

Top
#72949 - 2003-02-14 10:20 PM Re: FindMe KiXform
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Thats too bad. The WINSCL.exe method is more dependable anyhow. Just trying to find a way of getting same results without extra .exe file. Thanks for testing it though.
Top
Page 2 of 3 <123>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.078 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org