Jump to content

Noobie question, gethostbyaddr isn't giving me an output


Go to solution Solved by BrewManNH,

Recommended Posts

I may mess up with pointers and structs a little but, how I'm not getting a proper output? I was expecting to get my lan hostname using this (yes ping to that address gives the hostname)

I'm always getting "0"

$uip = DllCall("wsock32.dll", "long", "inet_addr", "str", "192.168.1.4")[0]
$call = DllCall("wsock32.dll", "long_ptr", "gethostbyaddr", "long_ptr", $uIP, "int", 4, "int", 2)
ConsoleWrite(DllStructGetPtr($call,1)&@LF)
Exit

arrayDisplay ouput:

Row|Col 0
[0]|0x00000000
[1]|67217600
[2]|4
[3]|2

What am I messing up here?  :mellow:

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

For a start inet_addr returns ulong, not long.

Next, you are passing an array to a param that expects a string.

The list goes on, you should start by doing some error checking after your calls to dll.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

being long or ulong still returns 67217600

I'm passing the [0] value of $uIP array :)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Yes, I see now.

in any case you should pass correct type.

You might get away with it and you might not, but I doubt it when the param you are passing it to expects a string.

You wont know until you check for errors.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

that's all the code to get the other lan computer name, I'm also trying with WMI using System.Net.Dns.GetHostEntry() but I don't know how to create an object for System class

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

This is the updated code, still outputing the 0

Local $uip = DllCall("wsock32.dll", "ulong", "inet_addr", "str", "192.168.1.4")[0]
$call = DllCall("wsock32.dll", "ptr", "gethostbyaddr", "ptr", $uIP, "int", 4, "int", 2)
ConsoleWrite(DllStructGetPtr($call,1)&@LF)
Exit

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • Solution

You should look in the Inet.au3 file for the function _TCPIPToName function to see how it is done in there.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 wow nice, tried on my local ip (since is the only one active now) and got @ERROR = 4, @Extended = 10093 = WSANOTINITIALISED
 
Sem_T_tulo.png

I don't know what to do now  :huh2:

DllCall($hDll_Ws2_32, "ptr", "gethostbyaddr", "ptr*", $vBinIP, "int", 4, "int", $iAF_INET) returned 0 (what was happening), and then called WSAGetLastError to get the error, should I call 

WSAStartup before running gethostbyaddr?  :think:

EDIT: If WSAStartup is really necessary, I don't know how should I create this struct WSADATA, and how do I put the wsock32 versions in a byte

I know that LByte is the first 4bits (right?)

HByte is the last 4bits, but if the version is 2.2 how do I put it in bits? :s bits are 0 or 1 

Edited by Kyan

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

If you look at the help file entry for _TCPIPToName, you'll see that you need to use TCPStartUp() before you can use the TCP functions, so I'm assuming you'd need to do that with your DLLCall as well.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Indeed, works :D only took 26ms to fetch the other host name ^_^

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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...