Jump to content

network printer name from IP


Recommended Posts

I am adding on to my printing script to display a selected printers default name as a label. Currently the script works by the user entering the ip address of the printer. I want to be able to take that ip address and return the printer's name.

I tried using _iptoname but have not been able to return anything :(

#include <GuiConstants.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <iNet.au3>

$x = 1
$i = 0
Global $ip
Global $ipen
Global $ipme
Global $ipin
Global $ftpr
Global $prin
Global $ip[$x]

$ip = IniReadSection(@WorkingDir & "\printip.ini", "ips")

GUICreate("IP Print", 250, 120, -1, -1, -1, $WS_EX_ACCEPTFILES)
$ipen = GUICtrlCreateCombo("", 1, 50)
GUICtrlCreateLabel("Select IP", 1, 32, 45, 15)

For $x = 1 To UBound($ip) - 1
    GUICtrlSetData($ipen, $ip[$x][1] & "|")
Next

$ipme = GUICtrlCreateInput("Enter IP", 1, 3, 100, 20)
$ipin = GUICtrlCreateButton("Save IP", 105, 1)
$ftpr = GUICtrlCreateInput("", 1, 97, 100, 20)
GUICtrlSetState($ftpr, $GUI_DROPACCEPTED)
$prin = GUICtrlCreateButton("Print", 105, 94)
GUICtrlCreateLabel("Drag File Here", 1, 77, 75, 15)
$ptnm = GUICtrlCreateLabel("Printer Name", 58, 32, 65, 15)

GUISetState(@SW_SHOW)

main()

Func main()
    TCPStartup()

    While 1
        $msg = GUIGetMsg()

        $lbl = GUICtrlRead($ipen)
        $ptr = _TCPIpToName($lbl, 1)
        If IsArray($ptr) Then
            MsgBox(0, "", $lbl & " " & $ptr[1])
            GUICtrlSetData($ptnm, $ptr[1], "Printer Name")
        EndIf

        If $msg = $ipin Then
            Do
                $i += 1
                $chk = IniRead(@WorkingDir & "\printip.ini", "ips", $i, "")
            Until $chk = ""
            $nwip = GUICtrlRead($ipme)
            IniWrite(@WorkingDir & "\printip.ini", "ips", $i, $nwip)

            GUICtrlSetData($ipen, "")

            For $x = 1 To UBound($ip) - 1
                GUICtrlSetData($ipen, $ip[$x][1] & "|")
            Next

        ElseIf $msg = $prin Then

            print()

        ElseIf $msg = $GUI_EVENT_CLOSE Then
            GUIDelete()
            Exit (1)

        EndIf

    WEnd

EndFunc   ;==>main

Func print()

    $ipad = GUICtrlRead($ipen)
    $flad = GUICtrlRead($ftpr)

    If $ipad = "" Then
        MsgBox(0, "Error", "No IP Selected", 10)
        main()
    EndIf

    If $flad = "" Then
        MsgBox(0, "Error", "No File Selected", 10)
        main()
    EndIf

    RunWait(@ComSpec & ' /c lpr -S "' & $ipad & '" -P raw -o l -d "' & $flad & '"')
    main()

EndFunc   ;==>print

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

An interesting tidbit, courtesy of pptfaq.com, of all places:

Sometimes the simplest, fastest way is to use good ol' DOS:

  • Open a command prompt window (choose Start, Run; type CMD then click OK)
  • In the command prompt window, type NET VIEW
  • That gives you a list of computers on your network. Note the name of the one that your printer's connected to.
  • Next, type NET VIEW \\server-name (substitute the name of the computer you chose above for "server-name")
  • That gives you a list of the resources shared by that computer; your printer's name should be on the list
I don't have a network printer to test it on, but you might be able to feed it the ip address and have it resolve the name.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

An interesting tidbit, courtesy of pptfaq.com, of all places:I don't have a network printer to test it on, but you might be able to feed it the ip address and have it resolve the name.

Thanks, I will look into that.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I can locate the printer with net view, but there is nothing for autoit to compare the ip address it has with the list of printers given from net view :(

I have also tried

ping -a

and

nbtstat

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Developers

You will have to add the IP addresses to your DNS server when you want to be able to retrieve a hostname that belongs to an IP address.

The Netview command will show the available SHARES for the specified server but this will only work when al printers have a share.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I may have to skip this feature then because changes to the network is off limits to me :(

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...