Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

How to use gethostbyname with max script

How to use gethostbyname with max script

YASUSHI_EMOTO
Enthusiast Enthusiast
361 Views
1 Reply
Message 1 of 2

How to use gethostbyname with max script

YASUSHI_EMOTO
Enthusiast
Enthusiast

If I wanted to get the IP address of my Windows PC in Python, I would use the following code

import socket
host = socket.gethostname()
ipaddress = socket.gethostbyname(host)

 

I want to do this in Max Script, so I wrote the following code, but it did not work.

socket = python.import "socket"
host = socket.gethostname
ipaddress = socket.gethostbyname host

 

Error message is this

-- Error occurred in anonymous codeblock; filename: ; position: 14; line: 1
-- Type error: Call needs function or class, got: undefined
-- MAXScript callstack:
--	thread data: threadID:24508
--	------------------------------------------------------
--	[stack level: 0]
--	In top-level
-- Error occurred in anonymous codeblock; filename: ; position: 43; line: 2
-- Unknown property: "gethostname" in undefined
-- MAXScript callstack:
--	thread data: threadID:24508
--	------------------------------------------------------
--	[stack level: 0]
--	In top-level
-- Error occurred in anonymous codeblock; filename: ; position: 75; line: 3
-- Unknown property: "gethostbyname" in undefined
-- MAXScript callstack:
--	thread data: threadID:24508
--	------------------------------------------------------
--	[stack level: 0]
--	In top-level

 

How can I use gethostbyname?

0 Likes
Accepted solutions (1)
362 Views
1 Reply
Reply (1)
Message 2 of 2

Swordslayer
Advisor
Advisor
Accepted solution

Your simplified example works (once the function call is completed with parentheses), what does the complete code that gives you errors look like?

0 Likes