mIRC Home    About    Download    Register    News    Help

Print Thread
#263552 17/08/18 05:56 PM
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
Some kind of identifier for returning your LAN/WLAN IP would be nice.

At the minute I have to use some PHP code bytecode compiled as an exe to do this.


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Code:
alias localip {
  .comopen a wbemScripting.swbemLocator | .comclose a $com(a,connectserver,3,bstr,.,bstr,root\cimv2,dispatch* b)
  .comclose b $com(b,execquery,3,bstr,SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True ,dispatch* c)
  var %b $comval(c,0),%r
  while (%b) {
    if ($comval(c,%b,DHCPEnabled)) %r = %r $comval(c,%b,DHCPServer)
    else %r = %r $comval(c,%b,IPAddress)
    dec %b
  }
  .comclose c
  return %r
}
You can try this, I might write something for the external ip later

Not a bad suggestion but it can be done without using 'php byte code'


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
Interesting.

This seems to return 192.168.0.1 instead of my current ip which is 192.168.0.3, though.


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Mar 2008
Posts: 93
B
Babel fish
Offline
Babel fish
B
Joined: Mar 2008
Posts: 93
Not sure, but DHCPServer sounds wrong in the if-part.

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Yes, that was not really correct. Before it wasn't possible to handle such result from mIRC's COM implementation, now with the latest beta it's possible:
Code
alias myips {
  .comopen loc WbemScripting.SWbemLocator
  .comclose loc $com(loc, ConnectServer, 3, dispatch* query)
  noop $com(query, ExecQuery, 3, bstr, Select * from Win32_NetworkAdapter WHERE NetConnectionStatus = 2, dispatch* adapter)
  var %a $comval(adapter,0)
  while (%a) {
    hadd -m getips $comval(adapter,%a,Index) $comval(adapter,%a,NetConnectionID)
    dec %a 
  }
  noop $com(query, ExecQuery, 3, bstr, Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True, dispatch* ips)
  var %cv $comval(ips,0)
  while (%cv) {
    if ($hget(getips,$comval(ips, %cv, Index)) != $null) {
      noop $comval(ips, %cv, IPAddress,&test).result
      breplace &test 0 32
      echo -s $bvar(&test,1-).text
    }
    dec %cv
 
  }
  :error
  if ($error || %err) {
    echo -a /myips: $v1
    reseterror
  }
  hfree getips
  .comclose query
  .comclose adapter
  .comclose ips
}
This finds the network adapter which are connected (status = 2) and then find the ip addresses belonging to them.

Note that when the value returned is an array like this, $comval(name,N,IPAddress) would return $null, but it now returns the first element in the array (while you can access the full array using a binvar and splitting on byte 0)


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard