question

yexioamu avatar image
0 Likes"
yexioamu asked yexioamu commented

How can i get the local ip in flexsim

I want to get the local ip in flexsim, could it be possible?

FlexSim 21.2.4
simulation
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Julie Weller avatar image Julie Weller commented ·

Hi @yexioamu, was Jason Lightfoot's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always comment back to reopen your question.

0 Likes 0 ·

1 Answer

Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered yexioamu commented

In the latest versions you can create this python module and set up a user command to access getLocalIP():

import socket

def getLocalIP():
    hostname=socket.gethostname()
    ip=socket.gethostbyname(hostname)
    return ip

(obviously you need to have Python installed for this solution)

PyMod.py

getLocalIP.fsm


In earlier versions you can write a dll function that will return the ip. You might also be able to do it via a command line that creates at text file you can load:

runprogram("cmd /C \"ipconfig|find \"IPv4 Address\" > ip2flexsim.txt\"\"")

pymod.py (123 B)
getlocalip.fsm (29.7 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

yexioamu avatar image yexioamu commented ·

My FlexSim is 21.2.4, it can use the dll function but not python; dll works well, but the cmd line run in flexsim can't output the ip, but when i run cmd in windows directly, it work well, maybe the reason is chinese encoding.

runprogram("cmd /C \"ipconfig|find \"IPv4 地址\" > ip2flexsim.txt\"\"")


0 Likes 0 ·
Ben Wilson avatar image Ben Wilson ♦♦ yexioamu commented ·

You could just remove your Chinese characters. The command still works fine:

runprogram("cmd /C \"ipconfig|find \"IPv4\" > ip2flexsim.txt\"\"")
0 Likes 0 ·
yexioamu avatar image yexioamu Ben Wilson ♦♦ commented ·

Yes, it works fine without Chinese characters "地址", thank you !

0 Likes 0 ·