Jump to content
Sign in to follow this  
ItsMillertime4u

DllCall to gethostbyname

Recommended Posts

ItsMillertime4u

I was wondering if anyone can help me on how to make an api call. I know AutoIt has the DllCall, DllOpen, DllClose, etc. but to be honest with you I can't make any sense out how to use them (this may be cause do to my lack of knowledge of C or C++). What I am trying to do is use the gethostbyname function. I found some examples of how to use the api here, but I really feel like I'm going blind when I try to read and then recreate it in AutoIt. I know AutoIt has the built in macro @IPAddress1 that could probably give me the same result, but I need to use this api specifically. I need to use this api specifically because I am trying to test the functionality of this. I would like to give a big thank you to anyone that may offer me some assistance.

Share this post


Link to post
Share on other sites
PsaltyDS

I was wondering if anyone can help me on how to make an api call. I know AutoIt has the DllCall, DllOpen, DllClose, etc. but to be honest with you I can't make any sense out how to use them (this may be cause do to my lack of knowledge of C or C++). What I am trying to do is use the gethostbyname function. I found some examples of how to use the api here, but I really feel like I'm going blind when I try to read and then recreate it in AutoIt. I know AutoIt has the built in macro @IPAddress1 that could probably give me the same result, but I need to use this api specifically. I need to use this api specifically because I am trying to test the functionality of this. I would like to give a big thank you to anyone that may offer me some assistance.

Uhmmm...

The code you are looking at is described thusly in the intro page to that site:

1.2. Platform and Compiler

The code contained within this document was compiled on a Linux PC using Gnu's gcc compiler. It should, however, build on just about any platform that uses gcc. Naturally, this doesn't apply if you're programming for Windows--see the section on Windows programming, below.

:D

The gethostbyname function is entirely in C. This common function is probably coded inside a brazillian different APIs and .dll's, but I don't think you would try to get to it from AutoIt by coding straight at the winsock.h library for Windows. Using one of the other APIs seems to not give you what you say you want.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
ItsMillertime4u

Ahh....I didn't catch that......but reallyall I am trying to do is use the gethostbyname api call and have it reurn the host ip to a messagebox or log or something that I can look at to test the functionality of the Citrix mod that I am making decribed here. I know Citrix already provides an app to do this, but the thing is I can only get this documented mod to work using their NetAppWin.exe application. So I am trying to see if I can create a different app/script that follows their documentation requirements to see if I can get something else to work.

Share this post


Link to post
Share on other sites
PsaltyDS

Ahh....I didn't catch that......but reallyall I am trying to do is use the gethostbyname api call and have it reurn the host ip to a messagebox or log or something that I can look at to test the functionality of the Citrix mod that I am making decribed here. I know Citrix already provides an app to do this, but the thing is I can only get this documented mod to work using their NetAppWin.exe application. So I am trying to see if I can create a different app/script that follows their documentation requirements to see if I can get something else to work.

I edited my post to add more info. The function gethostbyname is not an API, it is a C function that can be used as part of an API. In this case, while coding NetAppWin.exe in C, they used the gethostbyname function. Your given API is whatever interface NetAppWin.exe provides. Maybe only by GUI, maybe it exposes some COM objects, or maybe not.

:D

P.S. It looks like, if you want to write a C program yourself to use that function, you are supposed to use getaddrinfo now instead. If you want to use an API that is already there for AutoIt to use, try Windows WMI (VBS example):

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")

For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "DHCPEnabled: " & objItem.DHCPEnabled
    For Each strIPAddress in objItem.IPAddress
        Wscript.Echo "IPAddress: " & strIPAddress
    Next
     Wscript.Echo
Next

:D

P.P.S. I translate that this way in AutoIt:

$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$sQuery = "Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE"
$colItems = $objWMIService.ExecQuery ($sQuery)
$sResult = ""
For $objItem In $colItems
    $sResult &= "Caption: " & $objItem.Caption & @CRLF
    $sResult &= "DHCPEnabled: " & $objItem.DHCPEnabled & @CRLF
    For $strIPAddress In $objItem.IPAddress
        $sResult &= "IPAddress: " & $strIPAddress & @CRLF
    Next
    $sResult &= @CRLF
Next

MsgBox(64, "IP Addresses", $sResult)

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
ItsMillertime4u

I didn't realize that gethostbyname wasn't an api, I saw that Microsoft was recommending eveyone use getaddrinfo instead, but I was trying to shy away from that since the Citrix document did not mention anything about using getaddrinfo function. You mentioned earlier:

I don't think you would try to get to it from AutoIt by coding straight at the winsock.h library for Windows. Using one of the other APIs seems to not give you what you say you want.

, I guess that I am really just lost in this situation. I don't know how to program C, however I do know vbscript, html, and the basics of AutoIt. I've already tried using a WMI query (Win32_NetworkAdapterConfiguration), but I'm not having any luck on have the "UseClientIP Registry Works in a Session," work it always wants to return back the Citrix Server IP and not the client. I've added wscript.exe, cscript.exe, mshta.exe, and NetAppWin.exe to registry that Citrix describes but in result I only can get the ipaddress from the client to return in the NetAppWin.exe. I thought that maybe if I could find some way to do an api call or dll call or maybe something special in AutoIt, that maybe, just maybe I could use the gethostbyname, compile it in AutoIt, add it to the registry with hopes of it getting the client session ip. If you don't think this is possible please let me know. i would really like to explore all possible routes before contact Citirx, so that I can come at them with better insight of what I'm trying to do, and what I've tried to do in order to achieve my goal.

Share this post


Link to post
Share on other sites
PsaltyDS

Compile the AutoIt script I put at the bottom of post #4 and try it out locally and in your Citrix TS context. See if it shows the address of the Citrix server or the client. Of course, you'll have to follow through on the Citrix directions to add your compiled script to the list of apps that get the client IP.

I'm really curious how that will work, so post results...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
ItsMillertime4u

I compiled it, and I complied a vbscript version of, but both of them are echoing back the server ip and nic properties. I think I'm just going to have to contact Citrix with what I got and see if they can help me.

Share this post


Link to post
Share on other sites
PsaltyDS

I compiled it, and I complied a vbscript version of, but both of them are echoing back the server ip and nic properties. I think I'm just going to have to contact Citrix with what I got and see if they can help me.

Sorry we didn't make it work. Good luck with it.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  

×